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:
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
Please advise on what is best practices in setting up this type of environment using Docker.
If it helps, I am on a Mac, so using boot2docker.
Some Issues I've had:
- 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
"better" is relative. It all depends on what your needs are. Docker compose is for orchestrating multiple containers. If these images already exist in the docker registry, then it's better to list them in the compose file. If these images or some other images have to be built from files on your computer, then you can describe the processes of building those images in a Dockerfile.
Using multiple FROM in a single dockerfile is not a very good idea because there is a proposal to remove the feature. 13026
If for instance, you want to dockerize an application which uses a database and have the application files on your computer, you can use a compose file together with a dockerfile as follows
docker-compose.yml
Dockerfile
The answer is neither.
Docker Compose (herein referred to as compose) will use the Dockerfile if you add the build command to your project's
docker-compose.yml
.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 thebuild
command.You can specify the path to your individual Dockerfiles using
build /path/to/dockerfiles/blah
where/path/to/dockerfiles/blah
is where blah'sDockerfile
lives.In my workflow, I add a Dockerfile for each part of my system and configure it that each part could run individually. Then I add a docker-compose.yml to bring them together and link them.
Biggest advantage (in my opinion): when linking the containers, you can define a name and ping your containers with this name. Therefore your database might be accessible with the name
db
and no longer by its IP.It is also seems that Compose is considered production safe as of 1.11, since https://docs.docker.com/v1.11/compose/production/ no longer has a warning not to use it in production like https://docs.docker.com/v1.10/compose/production/ does.
Dockerfiles are to build an image for example from a bare bone Ubuntu, you can add
mysql
calledmySQL
on one image andmywordpress
on a second image calledmywordpress
.Compose YAML files are to take these images and run them cohesively. for example if you have in your
docker-compose.yml
file a service calldb
:and a service called worpress such as:
then inside the mywordpress container you can use
db
to connect to your mySQL container. This magic is possible because your docker host create a network bridge (network overlay).Dockerfile
A Dockerfile is a simple text file that contains the commands a user could call to assemble an image.
Example, Dockerfile
Docker Compose
Docker Compose
is a tool for defining and running multi-container Docker applications.
define the services that make up your app in
docker-compose.yml
so they can be run together in an isolated environment.get an app running in one command by just running
docker-compose up
Example, docker-compose.yml