Fedora 24
Sponsored Link

Docker : Use Dockerfile
2016/06/30
 
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management.
[1] The format of Dockerfile is [INSTRUCTION arguments] .
Refer to the following description for INSTRUCTION.
INSTRUCTION Description
FROM iIt sets the Base Image for subsequent instructions.
MAINTAINER It sets the Author field of the generated images.
RUN It will execute any commands when Docker image will be created.
CMD It will execute any commands when Docker container will be executed.
ENTRYPOINT It will execute any commands when Docker container will be executed.
LABEL It adds metadata to an image.
EXPOSE It informs Docker that the container will listen on the specified network ports at runtime.
ENV It sets the environment variable.
ADD It copies new files, directories or remote file URLs.
COPY It copies new files or directories.
The differences of [ADD] are that it's impossible to specify remore URL and also it will not extract archive files automatically.
VOLUME It creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers
USER It sets the user name or UID.
WORKDIR It sets the working directory.

[2] For example, Create a Dockerfile to install httpd and add index.html, and also start httpd with 80 port.
[root@dlp ~]#
vi Dockerfile
# create new

FROM fedora
MAINTAINER serverworld <admin@srv.world>
RUN dnf -y install httpd
RUN echo "Hello DockerFile" > /var/www/html/index.html
EXPOSE 80
CMD ["-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]

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

[root@dlp ~]#
docker build -t serverworld/httpd:v1.0 .

Sending build context to Docker daemon 11.26 kB
Step 1 : FROM fedora
 ---> f9873d530588
Step 2 : MAINTAINER serverworld <admin@srv.world>
 ---> Running in 5f39adeb5f98
 ---> c2ac72fc0fc1
.....
.....
Removing intermediate container 3fa8b8079a88
Successfully built 86a11f268773

[root@dlp ~]#
docker images

REPOSITORY            TAG        IMAGE ID            CREATED             SIZE
serverworld/httpd     v1.0       86a11f268773        16 seconds ago      338.3 MB
images/fedora_httpd   latest     33906951c2a6        About an hour ago   544.9 MB
docker.io/fedora      latest     f9873d530588        9 days ago          204.4 MB

# run Container on background

[root@dlp ~]#
docker run -d -p 80:80 serverworld/httpd:v1.0

437c2504ca443659e535253682cd1055d9f79431fef41d4b22a19058eae69802
[root@dlp ~]#
docker ps

CONTAINER ID   IMAGE                    COMMAND                  CREATED             STATUS              PORTS                NAMES
437c2504ca44   serverworld/httpd:v1.0   "/usr/sbin/httpd -D F"   26 seconds ago      Up 23 seconds       0.0.0.0:80->80/tcp   angry_darwin

[root@dlp ~]#
curl http://localhost/

Hello DockerFile
Matched Content
 
Tweet