使用easy_install來安裝supervisor
cd /home/zhuyr/leanote [root@dev leanote]# cat Dockerfile FROM centos MAINTAINER zhuyr<304748716@qq.com> # supervisor配置文件路徑 ENV SUPERVISORD_CONF=/etc/supervisord.conf # supervisor臨時文件路徑(日誌文件、sock文件、pid文件) ENV SUPERVISORD_TMP_CONF=/tmp/supervisor # supervisor程序塊文件路徑,便是[program]塊 ENV SUPERVISORD_INCLUDE_FILE=/etc/supervisordfile # web管理界面的IP ENV SUPERVISORD_WEB_IP=* # web管理界面的PORT ENV SUPERVISORD_WEB_PORT=9001 # web管理界面的帳號 ENV SUPERVISORD_WEB_ACCOUNT=admin # web管理界面的密碼 ENV SUPERVISORD_WEB_PASSWORD=adminpass RUN mkdir -p ${SUPERVISORD_TMP_CONF} RUN mkdir -p ${SUPERVISORD_INCLUDE_FILE} RUN yum -y update RUN yum install -y python-setuptools wget telinit RUN wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O |python RUN easy_install supervisor RUN echo -e "[unix_http_server]\nfile=${SUPERVISORD_TMP_CONF}/supervisor.sock\n[inet_http_server]\nport=${SUPERVISORD_WEB_IP}:${SUPERVISORD_WEB_PORT}\nusername=${SUPERVISORD_WEB_ACCOUNT}\npassword=${SUPERVISORD_WEB_PASSWORD}\n[supervisord]\nlogfile=${SUPERVISORD_TMP_CONF}/supervisord.log\nlogfile_maxbytes=50MB\nlogfile_backups=10\nloglevel=info\npidfile=${SUPERVISORD_TMP_CONF}/supervisord.pid\nnodaemon=false\nminfds=1024\nminprocs=200\n[supervisorctl]\nserverurl=unix://${SUPERVISORD_TMP_CONF}/supervisor.sock\n[include]\nfiles = ${SUPERVISORD_INCLUDE_FILE}/*.ini" > ${SUPERVISORD_CONF} USER root EXPOSE 22 80 9001 RUN /usr/sbin/init & RUN /usr/sbin/telinit &
[root@dev leanote]# docker build -t zhuyr/supervisor:1.0 --rm --no-cache . [root@dev leanote]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE zhuyr/supervisor 1.0 e116f6895b37 About a minute ago 236.6 MB ubuntu 14.04 7c09e61e9035 7 days ago 187.9 MB
## 1.3 下載安裝包python
[root@test2 leanote]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.1.tgz [root@test2 leanote]# wget https://static.axboy.cn/leanote/leanote-linux-amd64-v2.6.1.bin.tar.gz
[root@dev leanote]# cat Dockerfile # zhuyr/leanote:2.6.1 # with mongodb FROM zhuyr/supervisor:1.0 MAINTAINER zhuyr<304748716@qq.com> ADD init.sh /root/init.sh #ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf ADD supervisord.conf /etc/supervisord.conf COPY leanote-linux-amd64-v2.6.1.bin.tar.gz /root/ COPY mongodb-linux-x86_64-3.0.1.tgz /root/ RUN mkdir -p /root/db && \ cd /root && \ tar -xvf /root/mongodb-linux-x86_64-3.0.1.tgz && \ tar -xvf /root/leanote-linux-amd64-v2.6.1.bin.tar.gz && \ mv /root/mongodb-linux-x86_64-3.0.1 /root/mongodb && \ mkdir -p /root/conf_bak && \ cp /root/leanote/conf/* /root/conf_bak && \ chmod a+x /root/init.sh && \ chmod a+x /root/leanote/bin/run.sh EXPOSE 9000 CMD ["/usr/bin/supervisord"] [root@dev leanote]#
[root@dev leanote]# cat supervisord.conf [supervisord] nodaemon=true [program:mongodb] command=/root/mongodb/bin/mongod --dbpath /root/db [program:leanote] command=/bin/bash -c "/root/init.sh && /root/leanote/bin/run.sh"
[root@dev leanote]# cat init.sh #!/bin/bash #set -m # 若是數據庫未初始化,則初始化數據庫 if [ ! -f "/root/db/already-init-db" ] ; then touch /root/db/already-init-db /root/mongodb/bin/mongorestore -h localhost -d leanote --dir /root/leanote/mongodb_backup/leanote_install_data/ fi # 若是配置文件不存在,則複製配置文件 if [ ! -f "/root/leanote/conf/app.conf" ] ; then cp /root/conf_bak/* /root/leanote/conf/ fi
[root@dev leanote]# ll 總用量 58876 -rw-r--r--. 1 root root 675 3月 7 20:33 Dockerfile -rw-r--r--. 1 root root 428 3月 7 20:32 init.sh -rw-r--r--. 1 root root 20717785 3月 7 20:35 leanote-linux-amd64-v2.6.1.bin.tar.gz -rw-r--r--. 1 root root 39554547 3月 7 20:35 mongodb-linux-x86_64-3.0.1.tgz -rw-r--r--. 1 root root 197 3月 7 20:31 supervisord.conf [root@dev leanoteDockerFile]#
[root@dev leanoteDockerFile]# docker build -t zhuyr/leanote:2.6.1 --rm --no-cache . [root@dev leanoteDockerFile]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE zhuyr/leanote 2.4 60896a4094b8 12 seconds ago 477.4 MB zhuyr/supervisor 1.0 e116f6895b37 15 minutes ago 236.6 MB ubuntu 14.04 7c09e61e9035 7 days ago 187.9 MB [root@dev leanoteDockerFile]#
[root@dev leanote]# docker run --name leanote -d -v /leanote/leanotedb:/root/db -v /leanote/conf/:/root/leanote/conf/ -v /leanote/files:/root/leanote/files -p 9000:9000 zhuyr/leanote:2.6.1
[root@test2 leanote]# docker exec -it leanote /bin/bash [root@33106c3f0054 bin]# pwd /root/mongodb/bin [root@33106c3f0054 bin]# ./mongo >show dbs;
leanote 0.078GB
local 0.078GB
> use leanote; switched to db leanote > db.createUser({ ... user:'zhuyr', ... pwd:'abc123', ... roles:[{role:'dbOwner',db:'leanote'}] ... }); Successfully added user: { "user" : "zhuyr", "roles" : [ { "role" : "dbOwner", "db" : "leanote" } ] } > db.auth("zhuyr","abc123"); 1 > #查看leanote配置文件 [root@33106c3f0054 leanote]# cd conf/ [root@33106c3f0054 conf]# pwd /root/leanote/conf [root@33106c3f0054 conf]# cat app.conf
## 4.問題處理linux
若是mongodb裏的leanote沒導入成功,則進入容器從新執行如下命令:web