Docker Compose与Dockerfile-哪个更好? [英] Docker Compose vs. Dockerfile - which is better?
问题描述
我一直在阅读和学习 Docker ,并且正在尝试正确选择要使用的Django设置.到目前为止,有两种情况:
I have been reading up and learning about Docker, and am trying to correctly choose the Django setup to use. So far there is either:
Docker Compose 或我知道Docker Compose
中使用了Dockerfiles
,但是我不确定是否将所有内容放入一个大的Dockerfile中,并使用多个FROM
命令来处理不同的图像?
I understand that Dockerfiles
are used in Docker Compose
, but I am not sure if it is good practice to put everything in one large Dockerfile with multiple FROM
commands for the different images?
我想使用几张不同的图像,包括:
I want to use several different images that include:
uwsgi
nginx
postgres
redis
rabbitmq
celery with cron
请提供关于使用 Docker 设置此类环境的最佳实践的建议.
Please advise on what are best practices in setting up this type of environment using Docker.
如果有帮助,我在Mac上,因此使用 boot2docker .
If it helps, I am on a Mac, so using boot2docker.
我遇到的一些问题:
- Docker Compose与Python3不兼容
- 我想容器化我的项目,所以如果一个大的Dockerfile 不理想,那么我觉得我需要使用Docker Compose对其进行分解
- 我可以将项目Py2& Py3兼容,因此倾向于django-compose
- Docker Compose is not compatible with Python3
- I want to containerize my project, so if one large Dockerfile is not ideal, then I feel I'd need to break it up using Docker Compose
- I am ok to make the project Py2 & Py3 compatible, so am leaning towards django-compose
推荐答案
答案都不是.
如果将build命令添加到项目的docker-compose.yml
,则Docker Compose(以下称为compose)将使用Dockerfile.
Docker Compose (herein referred to as compose) will use the Dockerfile if you add the build command to your project's docker-compose.yml
.
您的Docker工作流程应该是为要创建的每个映像构建合适的Dockerfile
,然后使用compose通过build
命令组装映像.
Your Docker workflow should be to build a suitable Dockerfile
for each image you wish to create, then use compose to assemble the images using the build
command.
您可以使用build /path/to/dockerfiles/blah
指定单个Dockerfile的路径,其中/path/to/dockerfiles/blah
是blah的Dockerfile
所在的位置.
You can specify the path to your individual Dockerfiles using build /path/to/dockerfiles/blah
where /path/to/dockerfiles/blah
is where blah's Dockerfile
lives.
这篇关于Docker Compose与Dockerfile-哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!