部署docker-compose容器 [英] Deploying docker-compose containers

查看:101
本文介绍了部署docker-compose容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署使用docker-compose构建的应用程序,但感觉好像我的方向完全错误。

I'm trying to deploy an app that's built with docker-compose, but it feels like I'm going in completely the wrong direction.


  1. 我的所有工作都在本地工作- docker-compose up 在适当的网络和主机下启动我的应用。

  2. 我希望能够使用不同的 .env 文件在生产机上运行相同配置的容器和网络。

  1. I have everything working locally—docker-compose up brings up my app with the appropriate networks and hosts in place.
  2. I want to be able to run the same configuration of containers and networks on a production machine, just using a different .env file.

我当前的工作流程如下:

My current workflow looks something like this:

docker save [web image] [db image] > containers.tar
zip deploy.zip containers.tar docker-compose.yml
rsync deploy.zip user@server

ssh user@server
unzip deploy.zip ./
docker load -i containers.tar

docker-compose up

在这一点上,我希望当他们到达那里时能够再次运行 docker-compose up ,但这试图按照 docker-compose.yml 文件。

At this point, I was hoping to be able to run docker-compose up again when they get there, but that tries to rebuild the containers as per the docker-compose.yml file.

我有一种明显的感觉,就是我缺少某些东西。我应该在完整的应用程序上交付,然后在服务器上构建映像吗?如果要从注册表中存储/加载图像,如何开始组成容器?

I'm getting the distinct feeling that I'm missing something. Should I be shipping over my full application then building the images at the server instead? How would you start composed containers if you were storing/loading the images from a registry?

推荐答案

问题是我正在使用在开发和生产中使用相同的docker-compose.yml文件。

The problem was that I was using the same docker-compose.yml file in development and production.

应用程序服务未指定存储库名称或标签,因此当我运行 docker-compose up ,它只是试图在我应用程序的源代码目录(服务器上不存在)中构建Dockerfile。

The app service didn't specify a repository name or tag, so when I ran docker-compose up on the server, it just tried to build the Dockerfile in my app's source code directory (which doesn't exist on the server).

我最终通过在本地docker-compose.yml中添加显式图像字段解决了问题。

I ended up solving the problem by adding an explicit image field to my local docker-compose.yml.

version: '2'
services:
  web:
    image: 'my-private-docker-registry:latest'
    build: ./app

然后创建用于生产的替代撰写文件:

Then created an alternative compose file for production:

version: '2'
services:
  web:
    image: 'my-private-docker-registry:latest'
    # no build field!

在本地运行 docker-compose build 后, Web服务映像是使用存储库名称 my-private-docker-registry 和标签 latest 构建的。

After running docker-compose build locally, the web service image is built with the repository name my-private-docker-registry and the tag latest.

然后只是将映像推送到存储库的一种情况。

Then it's just a case of pushing the image up to the repository.

docker push 'my-private-docker-registry:latest'

并运行 docker pull ,可以安全地停止并使用新映像重新创建正在运行的容器。

And running docker pull, it's safe to stop and recreate the running containers, with the new images.

这篇关于部署docker-compose容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆