Composing Docker Environments: Services, Images and Builds21 Sep 2016
Today we continue talking about Docker Compose, following the last post. We are going to lay out a foundation to build our environment, commit by commit, and also explore the concepts of services, images and builds.
git commit -m ‘first commit’
Instead of throwing code snippets over these pages, I’ll use this GitHub repository to store and organize our journey. This is not something planned, neither do I have a draft, but I’ll try to put everything together commit by commit. If you have any tip during the read, drop a comment and I’ll be glad to discuss it.
To start, clone the repository, checks out the right tag and run docker-compose:
If everything goes well, you should be able to see the Django Hello World page at
http://localhost:8000. Otherwise, yell at me in the comments or create a issue in GitHub.
Oh, this is the versions I’m running right now:
To the content!
So, services, images and builds. What is these things?
In Docker Compose, each stack of your application is a service. It can be your framework, database, cache service, web server, proxy and so on. The service has its own configuration, like exposed ports, mounted volumes and entrypoint commands. The neat about services is that it can be scaled! One web server can’t handle the traffic? Throw more ten of them!
On our current environment, we got two services:
web, the first being an image and the last, a build. Excuse me?
The first is easy!
db is a Postgres image pulled from Docker Hub and executed without any customization. It just pulls and run. In the image documentation you can read about how it is built and various ways configure it.
On the other hand,
web is a build created with a Dockerfile, that is what this parameter means. The accepted parameters can be just a directory with a Dockerfile, a
context with a alternative file and even a mix of
image, where Compose will create a build named by the image parameter value. See below:
The Dockerfile is exactly the same from Docker. You can view the one I’m using here.
This is it for today folks! I hope your understanding of services, images and builds are clearer now If you got any issue, let me know!