Step1. apache2 & ubuntu
1.
docker pull ubuntu
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest f643c72bc252 5 weeks ago 72.9MB
2.
docker run -it --name=myApp -v /Users/xieheng/gitspace/supervisorTest/html:/var/www/html -v /Users/xieheng/gitspace/supervisorTest/log:/var/log -p 80:80 -p 143:143 f643c72bc252 /bin/bash
3. in the container, install apache2
root@74b1ae3f7684:/etc/apache2#apt-get update && apt-get install apache2
root@74b1ae3f7684:/etc/apache2#echo "ServerName localhost" >> /etc/apache2/apache2.conf
4.
root@74b1ae3f7684:/etc/apache2# cd sites-enabled/
root@74b1ae3f7684:/etc/apache2/sites-enabled# ls
000-default.conf
root@74b1ae3f7684:/etc/apache2/sites-enabled# vi 000-default.conf
change below:
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
to
ErrorLog /var/log/apache_error.log
CustomLog /var/apache_access.log combined
5. start apache2
service apache2 start
goto browser localhost, confirm server is running
apache2 在/etc/init.d/下
6.切换到apachectl
root@74b1ae3f7684:/etc/init.d# whereis apachectl
apachectl: /usr/sbin/apachectl
root@74b1ae3f7684:/etc/init.d#apachectl stop
root@74b1ae3f7684:/etc/init.d#apachectl start
切换确认localhost browser的情况,
后面要用supervisor + apachectl 控制
Step2. supervisor & apache2
7. 安装supervisor
root@74b1ae3f7684:/etc# apt-get install supervisor
root@74b1ae3f7684:/etc# cd supervisor/
root@74b1ae3f7684:/etc/supervisor# ls
conf.d supervisord.conf
root@74b1ae3f7684:/etc/supervisor# vi supervisord.conf //确认一下conf.d目录下所有的*.conf被包含
root@74b1ae3f7684:/etc/supervisor# cd conf.d
8. config supervisor
root@74b1ae3f7684:/etc/supervisor/conf.d# vi apache.conf
apache.conf的内容如下:
[program:apache]
command=apache2ctl -c "ErrorLog /dev/stdout" -DFOREGROUND
autostart=true
autorestart=true
startretries=1
startsecs=1
redirect_stderr=true
stderr_logfile=/var/log/myapache.err.log
stdout_logfile=/var/log/myapache.out.log
user=root
killasgroup=true
stopasgroup=true
最后两行:
killasgroup=true
stopasgroup=true
主要是为了防止apachectl 停止了父进程之后,子进程还在跑,成为进程孤儿。
9. reload
root@74b1ae3f7684:/etc/supervisor/conf.d# supervisorctl reread
error: <class 'FileNotFoundError'>, [Errno 2] No such file or directory: file: /usr/lib/python3/dist-packages/supervisor/xmlrpc.py line: 560
出现以上error的原因,是因为conf中有一些错误,需要再check 一下
先用apachectl stop 停止现有进程,再试一下
root@74b1ae3f7684:/etc/supervisor# supervisorctl reload
此时到browser 上确认,可以看到apache server在running
10. 如何停止正在运行的的apache
【待定】Simulate一下apache 停止和重启的过程
如果用apachectl stop 停止后,并没有看到自动启动,
直到使用supervisorctl reload ,因此需要再确认一下
Step3. make docker images
11.
xieheng@XiehengnoMacBook-Pro supervisorTest % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
74b1ae3f7684 f643c72bc252 "/bin/bash" 2 hours ago Up 2 hours 0.0.0.0:80->80/tcp, 0.0.0.0:143->143/tcp myApp
xieheng@XiehengnoMacBook-Pro supervisorTest % docker commit 74b1ae3f7684 xieheng/supervisor4apache:0102
sha256:a4f504b0f2ab73bfbc1eaaf266625caf3fc20ab6e1c6ea778a074dcecb15e8ab
xieheng@XiehengnoMacBook-Pro supervisorTest % docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xieheng/supervisor4apache 0102 a4f504b0f2ab 4 seconds ago 284MB
ubuntu latest f643c72bc252 5 weeks ago 72.9MB
上面可以看到新的image 已经做成,
12. 然后推送到dokcer hub:
xieheng@XiehengnoMacBook-Pro supervisorTest % docker push xieheng/supervisor4apache:0102
The push refers to repository [docker.io/xieheng/supervisor4apache]
64233482fcb5: Pushed
f6253634dc78: Mounted from library/ubuntu
9069f84dbbe9: Mounted from library/ubuntu
bacd3af13903: Mounted from library/ubuntu
0102: digest: sha256:ec4b127d4d0d93966834bc0486a74201187e7a3eef60b53cac3aea025bdadfe4 size: 1155
ref:
https://www.garron.me/en/linux/apache-static-site-docker-ubuntu.html
http://jackmorrison.me/2015/02/23/controlling-apache-with-supervisor.html
网友评论