CentOS 6
Sponsored Link

Docker : Use Dockerfile#22015/06/27

 
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management.
[1] For example, Create a Dockerfile to install httpd and add index.html.
[root@dlp ~]#
vi Dockerfile
# create new

FROM centos
MAINTAINER serverworld <admin@srv.world>
RUN yum -y install httpd
RUN echo "Hello DockerFile" > /var/www/html/index.html
CMD which httpd

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

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

Sending build context to Docker daemon 10.24 kB
Step 0 : FROM centos
 ---> 7322fbe74aa5
Step 1 : MAINTAINER serverworld <admin@srv.world>
 ---> Running in fa5364b3d41f
 ---> 57d8fd36b7f7
.....
.....
Removing intermediate container 6c41d45193a7
Successfully built 277e531b42be

[root@dlp ~]#
docker images

REPOSITORY          TAG         IMAGE ID          CREATED             VIRTUAL SIZE
serverworld/httpd   v1.0        4085b96acc22      4 seconds ago       268.4 MB
centos              latest      7322fbe74aa5      8 days ago          172.2 MB
centos              7           7322fbe74aa5      8 days ago          172.2 MB
centos              centos7     7322fbe74aa5      8 days ago          172.2 MB

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

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

/usr/sbin/httpd
# 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