Docker + your development and production environments
As a developer I’m used to have at least 2 environments of all projects - development and production. Since I’ve been using Docker this routine seemed to be more comfortable until …
What if I want to run my project simultaneously in both environments? Boom, el problem! Why? Let’s dive into that.
When I started using Docker and I get too far too use docker-compose I’ve created my first docker-compose.yml file. Then I used to happily run this:
docker-compose up
and my project was running. Amazing.
That was cool for dev environment. Once I’ve needed to create production set-up I created new file docker-compose.prod.yml and when I wanted to run production set-up I’ve used to run this:
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
and Docker took default file + my production file, merged them into one configuration and project was up in production set-up.
But what if I want to have these set-ups running side by side? When you run these two commands in two terminals
docker-compose up
and
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
Docker will end up with errors like conflict names, containers etc. I was like
Basically all you need to know is you have to create 2 separate docker files (so NOT one as base and one as override). In these files you need to name your services uniquely and then run docker-compose with -p param with project name for each environment. So step by step:
- Two docker files — one named like
docker-compose.dev.ymland seconddocker-compose.prod.yml. - Name your services uniquely across your whole computer. When I use Redis I name my redis image like
redis-PROJECT_NAME-devso i.e.
redis:
image: redis:3.2
container_name: redis-my-app-dev
Even your app has to have unique name:
app:
container_name: my-app-dev
- Run docker-compose with given project name like:
docker-compose -f docker-compose.prod.yml -p my-app-prod up
Leave Docker + your development and production environments to:
Read more #docker posts
Best Posts From n1
We have not curated any of n1-cz's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From n1
- How to mount host share directory in Virtualbox Linux system
- Project documentation aka own wiki(ish) docs
- How to publish a package to PyPI
- Postgres and date subtracting
- Twitter on blockchain
- Docker + your development and production environments
- Django’s new Extract*() classes
- Docker + SQLite 3
- Vue.js - init a component inside a component programmatically
- Gunicorn — autoreload app