由于启动一个平台所需要的服务过多,包括nginx、celery、gunicorn、django(可将以上依赖打包到镜像中)等
所以把所有的命令写到shell中;
run.sh如下:
/root/miniconda3/bin/nginx -c /root/miniconda3/etc/nginx/sites.d/default-site-user.conf;
cd /projectpath;/usr/bin/nohup /root/miniconda3/bin/gunicorn user.wsgi:application -c gunicorn.conf.py --bind=0.0.0.0:5000 &
cd /projectpath;/usr/bin/nohup /root/miniconda3/bin/celery -A user worker -n task@%h -l info -Q task -c 4 > log/task.stdin.log 2> log/task.error.log &
docker启动:
docker run --restart=unless-stopped -dit -v /projectpath:/projectpath -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -e DOCKER_HOST="unix:///var/run/docker.sock" --name projectname --net host -d docker-images:latest /bin/bash /run.sh-path
注意:
1.需将run.sh及项目所在路径挂在进docker中,
2.-v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker 表示将docker挂载进镜像中,这样可在docker内查看容器运行情况
3.--restart=unless-stopped表示自动重启
4.--net host 表示与宿主机共享ip端口



