Docker + your development and production environments

in #docker4 years ago (edited)

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 and when I wanted to run production set-up I’ve used to run this:

docker-compose -f docker-compose.yml -f 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


docker-compose -f docker-compose.yml -f 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:

  1. Two docker files — one named like second
  2. Name your services uniquely across your whole computer. When I use Redis I name my redis image like redis-PROJECT_NAME-dev so i.e.
    image: redis:3.2
    container_name: redis-my-app-dev

Even your app has to have unique name:

    container_name: my-app-dev
  1. Run docker-compose with given project name like:
docker-compose -f -p my-app-prod up

More on Github
Related Stack overflow question.

Coin Marketplace

STEEM 0.25
TRX 0.07
JST 0.031
BTC 22888.71
ETH 1677.82
USDT 1.00
SBD 3.15