0

我正在使用 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-composeing 东西的过程自动化,但可能有更好的工具来解决这个问题。

4

1 回答 1

1

我正在远程构建图像。这意味着将构建图像所需的整个源推送到网络上。对于从阿根廷发送到美国一些虚拟服务器的超过 400MB 数据的一些图像,被证明非常缓慢。

解决方案是完全改变对我的堆栈进行 docker 化的方法:

  • 我没有使用 Dockerfile 即时构建图像,而是ARG修改了我的源应用程序,它是 docker 图像,以在运行时通过环境变量接受选项。
  • 使用 DockerHub 自动构建,与 GitHub 集成。

这意味着我只通过 git 推送更改——而不是整个源代码。然后 DockerHub 构建镜像。

然后我docker-compose pulldocker-compose up -d我的网站。

免费的替代方案是运行您自己的自托管 docker 注册表和/或可能是 GitLab,因为它最近发布了自己的 docker 映像注册表:https ://about.gitlab.com/2016/05/23/gitlab-container-registry/ 。

于 2017-04-11T19:59:29.610 回答