httpd.service 文件路径:/lib/systemd/system/httpd.service
[root@docker-0002 ~]# mkdir apache
[root@docker-0002 ~]# cd apache
拷贝动态页面到docker-0002的/root/apache/
[root@ecs-proxy ~]# scp /root/5/public/info.php 192.168.1.32:/root/apache/
[root@docker-0002 apache]# echo 'Welcome to The Apache.' > index.html
[root@docker-0002 apache]# tar czf myweb.tar.gz index.html info.php
[root@docker-0002 apache]# vim Dockerfile
FROM mycentos:latest
RUN yum install -y httpd php && yum clean all
ENV LANG=C
ADD myweb.tar.gz /var/www/html/
WORKDIR /var/www/html/
EXPOSE 80
CMD ["/usr/sbin/httpd", "-DFOREGROUND"]
[root@docker-0002 apache]# docker build -t myapache:latest .
[root@docker-0002 apache]# docker images #可以看到有myapache的镜像
[root@docker-0002 apache]# docker rm -f $(docker ps -aq)
[root@docker-0002 apache]# docker run -itd --name myhttpd myapache:latest
[root@docker-0002 apache]# curl http://172.17.0.2/
Welcome to The Apache.
[root@docker-0002 apache]# docker rm -f myhttpd
myhttpd
#先手工做一遍
[root@docker-0002 apache]# docker run -it mycentos:latest
[root@dfd4e3d6dd96 /]# yum -y install php-fpm
#找service文件
[root@dfd4e3d6dd96 /]# cat /lib/systemd/system/php-fpm.service
...
ExecStart=/usr/sbin/php-fpm --nodaemonize
...
[root@dfd4e3d6dd96 /]# /usr/sbin/php-fpm --nodaemonize #前台启动,ctrl + C 终止
[root@docker-0002 ~]# mkdir phpfpm
[root@docker-0002 ~]# cd phpfpm
[root@docker-0002 phpfpm]# vim Dockerfile
FROM mycentos:latest
RUN yum install -y php-fpm && yum clean all
EXPOSE 9000
CMD ["/usr/sbin/php-fpm", "--nodaemonize"]
[root@docker-0002 phpfpm]# docker build -t phpfpm:latest .
启动php-fpm的容器,查看监听端口
[root@docker-0002 phpfpm]# docker images #有phpfpm的镜像
[root@docker-0002 phpfpm]# docker run -itd --name myphp phpfpm:latest
[root@docker-0002 phpfpm]# docker exec -it myphp ss -antlp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 127.0.0.1:9000 *:*
[root@docker-0002 phpfpm]# docker rm -f myphp
从ecs-proxy主机拷贝nginx的软件包到docker-0002主机
[root@ecs-proxy ~]# scp /root/5/public/nginx-1.17.6.tar.gz 192.168.1.32:/root/
[root@docker-0002 ~]# useradd nginx
[root@docker-0002 ~]# yum install -y gcc make pcre-devel openssl-devel
[root@docker-0002 ~]# tar zxf nginx-1.17.6.tar.gz
[root@docker-0002 ~]# cd nginx-1.17.6/
[root@docker-0002 nginx-1.17.6]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
[root@docker-0002 nginx-1.17.6]# make && make install
[root@docker-0002 nginx-1.17.6]# echo 'Nginx is running !' >/usr/local/nginx/html/index.html
[root@docker-0002 nginx-1.17.6]# cd /usr/local
[root@docker-0002 nginx-1.17.6]# tar -czf nginx.tar.gz nginx
[root@docker-0002 ~]# mkdir /root/nginx
[root@docker-0002 ~]# cd /root/nginx
[root@docker-0002 nginx]# cp /usr/local/nginx.tar.gz ./
[root@docker-0002 nginx]# vim Dockerfile
FROM mycentos:latest
RUN yum install -y pcre openssl && useradd nginx && yum clean all
ADD nginx.tar.gz /usr/local/
WORKDIR /usr/local/nginx/html
EXPOSE 80
CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
[root@docker-0002 nginx]# docker build -t mynginx:latest .
[root@docker-0002 nginx]# docker images #有mynginx的镜像
[root@docker-0002 nginx]# docker run -itd --name mynginx mynginx:latest
[root@docker-0002 nginx]# curl http://172.17.0.2/
Nginx is running !
[root@docker-0002 nginx]# docker rm -f mynginx