最后发布: 2018-10-09 18:49:32


I recently started migrating my self-hosted services to docker . 我最近开始将自托管服务迁移到docker To simplify maintenance, I'm using docker-compose . 为了简化维护,我使用的是docker-compose Some of the containers depend on each other, others are independent. 一些容器彼此依赖,其他容器是独立的。

With more than 20 containers and almost 500 lines of code, maintainability has now decreased. 拥有20多个容器和近500行代码,可维护性现已降低。

Are there good alternatives to keeping one huge docker-compose file? 保留一个巨大的docker-compose文件是否有很好的替代方案?

docker docker-compose

That's a big docker-compose.yml! 这是一个很大的docker-compose.yml! Break it up into more than one docker-compose file. 将其分解为多个docker-compose文件。

You can pass multiple docker-compose files into one docker-compose command. 您可以将多个docker-compose文件传递到一个docker-compose命令中。 If the many different containers break up logically, one way of making them easier to work with is breaking apart the docker-compose.yml by container grouping, logical use case, or if you really wanted to you could do one docker-compose file per service (but you'd have 20 files). 如果许多不同的容器在逻辑上分解,一种使它们更容易使用的方法是通过容器分组,逻辑用例docker-compose.yml ,或者如果你真的想要你可以docker-compose.yml容器做一个docker-compose文件服务(但你有20个文件)。

You can then use a bash alias or a helper script to run docker-compose . 然后,您可以使用bash别名或帮助程序脚本来运行docker-compose

# as an alias
alias foo='docker-compose -f docker-compose.yml -f docker-compose-serviceA.yml -f docker-compose-serviceB-yml $@'

Then: 然后:

# simple docker-compose up with all docker-compose files
$ foo -d up

Using a bash helper file would be very similar, but you'd be able to keep the helper script updated as part of your codebase in a more straightforward way: 使用bash帮助程序文件非常相似,但是您可以通过更直接的方式将帮助程序脚本更新为代码库的一部分:


docker-compose -f docker-compose.yml \
  -f docker-compose-serviceA.yml \
  -f docker-compose-serviceB.yml \
  -f docker-compose-serviceC.yml \

Note: The order of the -f <file> flags does matter, but if you aren't overriding any services it may not bite you. 注:顺序-f <file>标志确实重要,但如果你不覆盖任何服务可能不会咬你。 Something to keep in mind anyway. 无论如何要记住一些事情。


You could look at kubernetes 你可以看看kubernetes

If you didn't want to go all in, you can use minikube 如果您不想全 ,可以使用minikube

or maybe kubernetes baked into docker on the edge channel for windows or mac but that is beta so perhaps not for a production system 或者kubernetes在windows或mac的边缘通道上烘烤到docker中,但这是beta版,所以也许不适用于生产系统