使用Docker Compose的服务器和客户端开发工作流程? [英] Development workflow for server and client using Docker Compose?
问题描述
我正在同时开发服务器及其客户端,并在Docker容器中进行设计。我正在使用Docker Compose进行链接,它可以很好地用于生产环境,但我不知道如何使其与开发工作流程一起使用,在该工作流程中,我每个人都运行一个shell。
I'm developing a server and its client simultaneously and I'm designing them in Docker containers. I'm using Docker Compose to link them up and it works just fine for production but I can't figure out how to make it work with a development workflow in which I've got a shell running for each one.
我的 docker-compose-devel.yml
:
server:
image: node:0.10
client:
image: node:0.10
links:
- server
我可以做 docker-compose up client
或甚至 docker-compose运行客户端
,但我想要的是同时为服务器和客户端运行的shell,这样我就可以在迭代开发时对两者进行快速更改。
I can do docker-compose up client
or even docker-compose run client
but what I want is a shell running for both server and client so I can make rapid changes to both as I develop iteratively.
我希望能够在一个窗口中执行 docker-compose run服务器bash
和 docker-compose run --no-deps client bash
在另一个窗口中。这样做的问题是,因为我使用的是 docker-compose run <,所以服务器的地址没有添加到客户端上的
/ etc / hosts
上/ code>而不是 up
。
I want to be able to do docker-compose run server bash
in one window and docker-compose run --no-deps client bash
in another window. The problem with this is that no address for the server is added to /etc/hosts
on the client because I'm using docker-compose run
instead of up
.
我能确定的唯一解决方案是使用 docker run
放弃Docker Compose进行开发。有更好的方法吗?
The only solution I can figure out is to use docker run
and give up on Docker Compose for development. Is there a better way?
推荐答案
这是我想出的一种解决方案请让我知道是否可以做得更好。
Here's a solution I came up with that's hackish; please let me know if you can do better.
docker-compose-devel.yml
:
server:
image: node:0.10
command: sleep infinity
client:
image: node:0.10
links:
- server
在窗口1:
docker-compose --file docker-compose-dev.yml up -d server
docker exec --interactive --tty $(docker-compose --file docker-compose-dev.yml ps -q server) bash
在窗口2中:
docker-compose --file docker-compose-dev.yml run client bash
这篇关于使用Docker Compose的服务器和客户端开发工作流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!