Running multiple Dockerize projects at the same time using PHP, MySQL, nginx

Viewed 2177

Problem

I have projects with docker-compose configuration with same configuration (PHP, MySQL, nginx). When I run one project with docker-compose up there is not a problem, but I need to switch between them to few times per day for development.

The problems:

  • the share configurations for same port for nginx
  • share configuration for default DB and connection (name and users)
  • domains for each project

I have

  • Docker for Mac - edge

For now

Right now simply run up and down -v each time. Mostly, project are on the same PHP version (should be) and MySQL.

Ideas

Load balancer

One of idea is to create configuration in main folder workspace, docker-compose with some loadbalancer that will is some rules will generate domain for given project with volume as main folder and with one MySql server and few DB - but this is raw idea.

Question

What solution is work with given situation?

  • propose any structure or docker configuration to solve independent configurations?

Update

My docker-compose files

version: '2.1'

Single server setup for dev

services:
  app:
    image: ${PHP_IMAGE}
    volumes:
     - ${COMPOSE_DIR}/../../:/var/www:cached
     - ${COMPOSER_HOME}:/root/.composer:cached
    depends_on:
     - db
    environment:
     - SYMFONY_ENV=${SYMFONY_ENV-prod}
     - SYMFONY_DEBUG
     - SYMFONY_HTTP_CACHE
     - SYMFONY_HTTP_CACHE_CLASS
     - SYMFONY_TRUSTED_PROXIES
     - DATABASE_USER
     - DATABASE_PASSWORD
     - DATABASE_NAME
     - DATABASE_HOST=db

  web:
    image: ${NGINX_IMAGE}
    volumes_from:
     - app:ro
    ports:
     - "8080:80"
    environment:
     - SYMFONY_ENV=${SYMFONY_ENV-prod}
     - MAX_BODY_SIZE=20
     - FASTCGI_PASS=app:9000
     - TIMEOUT=190
     - DOCKER0NET
    command: /bin/bash -c "cd /var/www && cp -a doc/nginx/ez_params.d /etc/nginx && bin/vhost.sh --template-file=doc/nginx/vhost.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"

  db:
    image: ${MYSQL_IMAGE}
    volumes:
     - ${COMPOSE_DIR}/entrypoint/mysql:/docker-entrypoint-initdb.d/:ro
    environment:
     - MYSQL_RANDOM_ROOT_PASSWORD=1
     - MYSQL_USER=$DATABASE_USER
     - MYSQL_PASSWORD=$DATABASE_PASSWORD
     - MYSQL_DATABASE=$DATABASE_NAME
     - TERM=dumb

Given this, As I told, I would want to have running projects with different PHP version. Each have same nginx configuration, then need somehow have possibility to run them, easily and simultaneously.

Understand answer of @Vladimir Kovpak, but working this way manually will generate a lot of work. Each project have own docker-compose config.

What would be perfect

Scenario 1

  • Go to project, run command to build correctly by docker-compose
    • Could do dev work
    • could have accessible page via some dynamic domains
  • run command to close project

Scenario 2

  • Go to project, run command to build correctly by docker-compose
  • Go to other project, run command to build correctly by docker-compose
  • Go to other project, run command to build correctly by docker-compose
    • Could do dev work
    • could have accessible page via some dynamic domains
  • run command to close project

Could work with all project at same time. The first step is proposition - any initialisation and closing would be fine, as not painful - should be quick and easy.

2 Answers
Related