This will show you the process of using Dockerfile to create a Docker image with Apache services.
Preparatory work:
First, create a Apache_centos working directory in which
[Email protected] ~]# mkdir apache_centos && cd Apache_centos
[email protected] apache_centos]# Touch Dockerfile run.sh
[Email protected] apache_centos]# mkdir sample
[email protected] apache_centos]# cat Dockerfile
From Docker.io/centos:latest
#设置继承来自我们创建的centos: Latest Mirror
Maintainer Waitfish from dockerpool.com
#创建者的基本信息
#设置环境变量, all operations are non-interactive
ENV Debian_frontend noninteractive
RUN echo "Asia/shanghai" >/etc/timezone #&& \
# dpkg-reconfigure-f noninteractive tzdata #这也是设置时区的
#注意这里要更改系统的时区设置, because the time zone is often used in Web applications, the default CentOS will make your application this program incredibly effective.
#需要使用yum需要执行这一步
RUN Yum Update
#安装sshd服务
RUN Yum install-y openssh-server
#安装wget
RUN Yum install-y wget
Workdir/usr/local/src
#下载并解压源码包
RUN wget http://mirrors.shuosc.org/apache//httpd/httpd-2.2.34.tar.gz
RUN TAR-XF httpd-2.2.34.tar.gz
Workdir httpd-2.2.34
#编译安装apache
RUN Yum install-y gcc make apr-devel Apr apr-util apr-util-devel pcre-devel
RUN./configure--prefix=/usr/local/apache2--enable-mods-shared=most--enable-so
RUN make
RUN make Install
#修改apache配置文件
RUN sed-i ' s/#ServerName www.example.com:80/ServerName localhost:80/g '/usr/local/apache2/conf/httpd.conf
#启动apache服务
Run/usr/local/apache2/bin/httpd
#启动sshd服务
#RUN systemctl Start Sshd.service
#复制服务启动脚本并设置权限
ADD run.sh/usr/local/sbin/run.sh
RUN chmod 755/usr/local/sbin/run.sh
#添加一个示例的Web站点, delete the files that are installed by default in the Apache folder and add the instances we added to the/var/www/html directory with a soft link
RUN mkdir-p/app && rm-fr/usr/local/apache2/html && ln-s/app/usr/local/apache2/html
COPY sample//app
#设置开机自启动
#COPY/usr/local/apache2/bin/httpd/etc/rc.d/init.d/httpd
#chkconfig--add httpd
#RUN Systemctl Enable Sshd.service
#RUN Systemctl Enable Httpd.service
#开放80端口
EXPOSE 80 22
Workdir/app
CMD ["/usr/local/sbin/run.sh"]
This article is from the "small White love life" blog, please be sure to keep this source http://sf1314.blog.51cto.com/13295031/1980710
Use Dockerfile to create a CentOS Docker image with Apache service 1