Fedora 23
Sponsored Link

Docker : Use Dockerfile#12015/11/12

 
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.
[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
CMD /usr/bin/whereis 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.78 kB
Step 0 : FROM fedora
 ---> c7d2f0130dae
Step 1 : MAINTAINER serverworld <admin@srv.world>
 ---> Running in 221f62606bce
 ---> d430c0909468
.....
.....
Removing intermediate container 3cb67d3a9aa5
Successfully built b6f3fceaba56

[root@dlp ~]#
docker images

REPOSITORY            TAG      IMAGE ID       CREATED           VIRTUAL SIZE
serverworld/httpd     v1.0     b6f3fceaba56   35 seconds ago    331.6 MB
docker.io/fedora      latest   c7d2f0130dae   9 days ago        204.3 MB

# execute without arguments, then the command specified by CMD is executed

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

httpd: /usr/sbin/httpd /usr/lib64/httpd /etc/httpd /usr/share/httpd /usr/share/man/man8/httpd.8.gz
# execute with arguments, then the command specified by CMD is overwritten and the arguments is executed

[root@dlp ~]#
docker run serverworld/httpd:v1.0 /usr/bin/cat /var/www/html/index.html

Hello DockerFile
Matched Content