一、环境
ubuntu 14.04
Docker version 1.9
二,准备工作
下载ubuntu image ---- docker pull ubuntu
新建apache目录 mkdir /apache 进入apache cd /apache
新建文件 Dockerfile touch Dockerfile
在apache 目录下 新建 index.html touch index.html
vi index.html 输入:
<head>
<title>this is a apache website</title>
</head>
<body>
<h1>APACHE WEB SERVER</h1>
</body>
vi Dockerfile 输入:
FROM ubuntu
MAINTAINER ZHONG
RUN apt-get -yqq update
RUN apt-get -yqq install apache2
VOLUME [ "/var/www/html" ]
WORKDIR /var/www/html
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
ADD index.html /var/www/html/index.html
EXPOSE 80
ENTRYPOINT [ "/usr/sbin/apache2" ]
CMD ["-D", "FOREGROUND"]
执行 docker build -t apache2 .
运行过程:
Sending build context to Docker daemon 3.584 kB
Sending build context to Docker daemon
Step 0 : FROM ubuntu
---> ca4d7b1b9a51
Step 1 : MAINTAINER ZHONG
---> Using cache
---> f0e90a7b69ae
Step 2 : RUN apt-get -yqq update
---> Using cache
---> 40df08b7667c
Step 3 : RUN apt-get -yqq install apache2
---> Using cache
---> 8fa66c005b6c
Step 4 : VOLUME /var/www/html
---> Using cache
---> 06b5a561f11e
Step 5 : WORKDIR /var/www/html
---> Using cache
---> b6cde5798a4c
Step 6 : ENV APACHE_RUN_USER www-data
---> Using cache
---> 96ec7b170148
Step 7 : ENV APACHE_RUN_GROUP www-data
---> Using cache
---> 9d3ae0d5867e
Step 8 : ENV APACHE_LOG_DIR /var/log/apache2
---> Using cache
---> b7d51b8e5f57
Step 9 : ENV APACHE_PID_FILE /var/run/apache2.pid
---> Using cache
---> 3f531e286929
Step 10 : ENV APACHE_RUN_DIR /var/run/apache2
---> Using cache
---> ad61f5cb1364
Step 11 : ENV APACHE_LOCK_DIR /var/lock/apache2
---> Using cache
---> 2b47f6124e3f
Step 12 : RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
---> Using cache
---> cd60364c0b00
Step 13 : ADD index.html /var/www/html/index.html
---> 83b2d9bee73b
Removing intermediate container 170c0ce429a3
Step 14 : EXPOSE 80
---> Running in 6afd600c7a00
---> 94dd79989202
Removing intermediate container 6afd600c7a00
Step 15 : ENTRYPOINT /usr/sbin/apache2
---> Running in 55f8e9152fc1
---> f6a274de4c0d
Removing intermediate container 55f8e9152fc1
Step 16 : CMD -D FOREGROUND
---> Running in 670d3d86455c
---> 1af1c53ef494
Removing intermediate container 670d3d86455c
Successfully built 1af1c53ef494
执行docker images,可以看到apache2 镜像
新建一个apache 容器 docker run --name apache -d -p 80:80 apache2
查看apache 容器 docker ps
查看apache 是否运行成功 curl http://127.0.0.1 ,根据反馈的内容 可以确定 apache容器的apache服务运行正常
本文出自 “昨夜雨疏风骤” 博客,请务必保留此出处http://zxx287856774.blog.51cto.com/3417296/1722165
原文地址:http://zxx287856774.blog.51cto.com/3417296/1722165