0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

dockerコンテナ作った(Dockerfileから)

Last updated at Posted at 2021-01-22

#イメージの作成

*コンテナ起動時にapacheが自動起動しない・・・なぜだ

追記
CMD /usr/sbin/apachectl -D FOREGROUND
にすれば自動起動した

Dockerfileを準備

mkdir -p /usr/local/etc/docker_files/test/
vi /usr/local/etc/docker_files/test/Dockerfile
FROM ubuntu

RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get install -y sudo
RUN sudo apt-get install -y vim
RUN sudo apt-get install -y curl
RUN sudo apt-get install -y tzdata
RUN sudo apt-get install -y php7.4

ADD ./home /home/
ADD ./php.ini /usr/local/etc/php/
ADD ./apache2 /usr/local/etc/
COPY ./startup.sh /usr/local/etc/
RUN chmod 744 /usr/local/etc/startup.sh

RUN ["sudo", "/bin/bash", "-c", "echo \"ServerName $HOSTNAME\" > /etc/apache2/conf-available/fqdn.conf"]
RUN a2enconf fqdn
#RUN apachectl start

EXPOSE 80
CMD ["/usr/local/etc/startup.sh"]
#ENV APACHE_RUN_USER www-data
#ENV APACHE_RUN_GROUP www-data
#ENV APACHE_PID_FILE /var/run/apache2.pid
#ENV APACHE_RUN_DIR /var/run/apache2
#ENV APACHE_LOG_DIR /var/log/apache2
#ENV APACHE_LOCK_DIR /var/lock/apache2
#CMD ["apachectl", "-D", "FOREGROUND"]
#RUN ["sudo", "/bin/bash", "-c", "/etc/init.d/apache2 start"]
#RUN ["sudo", "/bin/bash", "-c", "/usr/sbin/apachectl -D FOREGROUND"]

Dockerfileからイメージを作成

イメージあるかどうか確認

docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE

ビルド(イメージを作成)

docker build -t test /usr/local/etc/docker_files/test/

できたかどうか確認


docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
php74test    latest    b5f7bfd05352   58 seconds ago   297MB
ubuntu       latest    f63181f19b2f   24 hours ago     72.9MB

##コンテナ作成

docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
docker run --name container01 -it php74test:latest /bin/bash

Ctrl + P + Q でコンテナから出る
docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
a3270221bbd8   php74test:latest   "/bin/bash"   54 seconds ago   Up 53 seconds             container01
docker attach container01
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?