如何构造Docker项目以方便部署? [英] How can I structure my docker projects for easy deployment?
问题描述
现在,我在同一个文件夹中将应用程序的多个组件与一个由docker-compose
链接在一起
Right now I have multiple components of my application in the same folder linked together with a docker-compose
这在开发中确实很好用,但是当我要进行生产时,这有点模糊。如果保持这种结构,我将无法仅使用dockerhub来托管我的图像,因为链接它们的docker-compose将会丢失。如果我使用git下拉docker-compose,那么dockerhub的意义是什么?为什么不克隆我的整个仓库并每次运行 docker-compose up
?
This works really well in development, but when I want to push to production it's kind of fuzzy. If I keep this structure I cannot use only dockerhub to host my images because the docker-compose which links them will be missing. If I use git to pull down my docker-compose, what would be the point of dockerhub? Why not just clone my whole repo and run docker-compose up
each time?
我也可以存储每个组件分别在单独的github存储库中,将其推送到master时将其推送到dockerhub。然后,只需将它们从中心与dockercompose组合即可。这似乎也不太理想,因为必须克隆并推送到几个不同的存储库以进行影响系统的更改。
I could alternatively store each component separately in separate github repos, pushing them up to dockerhub when pushed to master. Then, simply combine them from the hub with a dockercompose. This seems less than ideal too, since one would have to clone and push to several different repos to make a change which effects the system.
您如何做到的?
推荐答案
查看新的(仍在试验中) docker-app
(2018年6月)
Check out the new (still experimental) docker-app
(June 2018)
它将允许您将docker-compose推送到DockerHub,以及通过dev和之间的设置差异(通过docker-compose)启动应用程序产品。
It will allow you to push your docker-compose to DockerHub, as well as launch your app (through docker-compose) with settings variations between dev and prod.
请参见示例:
您可以基于此撰写文件创建应用程序包:
You can create an Application Package based on this Compose file:
$ docker-app init --single-file hello
$ ls
docker-compose.yml
hello.dockerapp
新的网络w文件 hello.dockerapp
包含三个YAML文档:
The new new file hello.dockerapp
contains three YAML documents:
- 元数据
- 撰写文件
- 您的应用程序设置
请参见 在集线器上共享应用程序
您可以使用docker-app push将任何应用程序推送到集线器:
You can push any application to the Hub using docker-app push:
$ docker-app push --namespace myHubUser --tag latest
此命令将在本地Docker守护程序上创建名为
myHubUser / hello.dockerapp:latest
的映像,并将其推送到集线器。
This command will create an image named
myHubUser/hello.dockerapp:latest
on your local Docker daemon, and push it to the Hub.
这篇关于如何构造Docker项目以方便部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!