Ubuntu 16.04
Sponsored Link

Docker : Use Dockerfile#22016/06/17

Use Dockerfile and create Docker images automatically.
It is also useful for configuration management.
[1] For example, Create a Dockerfile to install Apache2 and add index.html, and also start Apache2 with 80 port.
vi Dockerfile
# create new

FROM ubuntu
MAINTAINER ServerWorld <admin@srv.world>

RUN apt-get update
RUN apt-get -y install apache2
RUN echo 'Hello DockerFile' > /var/www/html/index.html
RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh
RUN echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh
RUN echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh
RUN echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh
RUN chmod 755 /root/run_apache.sh
CMD /root/run_apache.sh

# build image ⇒ docker build -t [image name]:[tag] .

docker build -t apache_httpd:latest .

Step 10 : RUN chmod 755 /root/run_apache.sh
 ---> Using cache
 ---> 08e27423dcde
Step 11 : EXPOSE 80
 ---> Using cache
 ---> f1b699db5891
Step 12 : CMD /root/run_apache.sh
 ---> Using cache
 ---> bb537256b647
Successfully built bb537256b647

docker images

REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
apache_httpd            latest              bb537256b647        8 minutes ago       258.7 MB
my_image/ubuntu_httpd   latest              65d1b6d04b37        2 days ago          258.7 MB
my_image/ubuntu_sshd    latest              dff14a9cd0ff        2 days ago          214.5 MB
ubuntu                  latest              2fa927b5cdd3        3 weeks ago         122 MB

# run Container on background

docker run -d -p 80:80 apache_httpd

docker ps

CONTAINER ID    IMAGE           COMMAND                  CREATED         STATUS         PORTS                NAMES
e62458c61bab    apache_httpd    "/bin/sh -c /root/run"   11 seconds ago  Up 11 seconds>80/tcp   agitated_poitras

curl http://localhost/

Hello DockerFile
Matched Content