我正在使用 docker-compose 部署到远程主机。这是我的配置的样子:
# stacks/web.yml
version: '2'
services:
postgres:
image: postgres:9.6
restart: always
volumes:
- db:/var/lib/postgresql/data
redis:
image: redis:3.2.3
restart: always
web_server:
depends_on: [postgres]
build: ../sources/myapp
links: [postgres]
restart: always
volumes:
- nginx_socks:/tmp/socks
- static_assets:/source/public
sidekiq:
depends_on: [postgres, redis]
build: ../sources/myapp
links: [postgres, redis]
restart: always
volumes:
- static_assets:/source/public
nginx:
depends_on: [web_server]
build: ../sources/nginx
ports:
- "80:80"
volumes:
- nginx_socks:/tmp/socks
- static_assets:/public
restart: always
volumes:
db:
nginx_socks:
static_assets:
# stacks/web.production.yml
version: '2'
services:
web_server:
command: bundle exec puma -e production -b unix:///tmp/socks/puma.production.sock
env_file: ../env/production.env
sidekiq:
command: bundle exec sidekiq -e production -c 2 -q default -q carrierwave
env_file: ../env/production.env
nginx:
build:
args:
ENV_NAME: production
DOMAIN: production.yavende.com
我部署使用:
eval $(docker-machine env myapp-production)`
docker-compose -f stacks/web.yml -f stacks/web.production.yml -p myapp_production build -no-deps web_server sidekiq
docker-compose -f stacks/web.yml -f stacks/web.production.yml -p myapp_production up -d
虽然这在本地工作得很好,而且我过去用这种方法成功部署了几次,但现在它在构建“web_server”服务时挂起,最后显示一些超时错误,就像我在这个问题中描述的那样中描述的那样。
我认为问题源于我的慢速连接(阿根廷->美国的 DigitalOcean 服务器)和我尝试构建图像并推送它们而不是使用集线器托管的图像。
我已经能够通过将我的撰写配置克隆到服务器并docker-compose
直接在那里运行来进行部署。
问题是:有没有更好的方法来自动化这个过程?使用 docker-compose 即时构建图像是一种好习惯吗?
我一直在考虑将这个将源克隆到服务器和docker-compose
ing 东西的过程自动化,但可能有更好的工具来解决这个问题。