Docker Dockerfile Detailed Category: DevOps 2014-05-15 11:0921652 People readComments (0)CollectionReportDocker
directory (?) [+]
How to use
Dockerfile is used to create a custom image that contains user-specified software dependencies, and so on. Under current directory contains Dockerfile, use command build to create a new image and name it edwardsbean/centos6-jdk1.7:
Docker build-t edwardsbean/centos6-jdk1. 7 .
Dockerfile keywords
How to write a dockerfile, in the following format:
# Comment instruction Arguments
From
Based on which mirror
RUN
Install software with
Maintainer
Image Creator
Cmd
Container the command executed at startup, but only one cmd command in a dockerfile, and more than just the last cmd.
CMD is used primarily for container when the specified service is started, and when the command of Docker run is matched to a cmd command, the command executed by CMD is replaced. Such as:
Dockerfile:
CMD echo Hello World
Run a try:
[Email protected] PC:~/software/docker-image/centos-add-test$ Docker run Centos-cmdhello World
Once the command matches:
[Email protected] PC:~/software/docker-image/centos-add-test$ Docker run centos-cmd echo Hello Edwardsbeanhello Edwardsbean
EntryPoint
Container the command executed at startup, but only one entrypoint command can be in a dockerfile, and if multiple, only the last one is executed
entrypoint replaceable feature with no cmd
USER
Which user to use to run container
Such as:
entrypoint ["memcached"] USER Daemon
EXPOSE
Container the port on which the internal service is open. On the host to use also to start container, do host-container port mapping:
Docker 127.0.0.1:33301: centos6-ssh
The 22 port of the container SSH service is mapped to the 33301 port of the host
Env
Used to set environment variables, such as:
ENV LANG en_US. utf-8 ENV lc_all en_US. utf-8
ADD
Path of file <src> Copy to container file system <dest>
All files and folders that are copied to container have permissions of 0755,uid and GID 0
If the file is in a recognized compression format, Docker will help to decompress
If you want to add a local file, the local file must be in Docker build <path>, the specified <PATH> directory
If you want to add a remote file, the remote file must be in Docker build <path>, specified in the <PATH> directory. Like what:
Docker Build Github.com/creack/docker-firefox
Docker-firefox directory must have dockerfile and file to add
Note: Build using the Docker build-< Somefile method does not add the local file directly to container. Only add URL file.
Add is only run once at the time of the build image and will not reload when running container.
VOLUME
You can attach a local folder or other container folder to container.
Workdir
Switch directory, you can switch multiple times (equivalent to CD command), Run,cmd,entrypoint effective
Onbuild
Onbuild The specified command is not executed when the image is built, but is executed in its sub-image
See here
Docker Dockerfile Detailed