Running multiple Dockerize projects simultaneously using PHP, MySQL, nginx

Problem

I have projects with a configuration docker-composewith the same configuration (PHP, MySQL, nginx). When I run one project with docker-compose up, the problem does not arise, but I need to switch between them several times a day for development.

Problems:

  • single port sharing configuration for nginx
  • share configuration for default database and connection (name and users)
  • domains for each project

I have

  • Docker for Mac - edge

At the moment

Now just run upit down -vevery time. Basically, the project is on the same version of PHP (should be) and MySQL.

Ideas

Load balancer

- workspace, docker-compose loadbalancer, , MySql DB - .

?

  • ?

Update

: '2.1'

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

, , PHP. ​​ nginx, .

@ , . -.

1

  • , docker-compose
    • dev.

2

  • , docker-compose
  • , docker-compose
  • , docker-compose
    • dev.

. - , - .

+6
2

Portainer, -, , .

Portainer -, , - MySQL, PHP phpmyadmin, . , .

, IP- , .

, , , .

+4

nginx:
, :

docker run -ti --name nginx-1 -p 8081:80 nginx:latest
docker run -ti --name nginx-2 -p 8082:80 nginx:latest

nginx server_name s, :

nginx-1 -> server_name one.dev;
nginx-2 -> server_name two.dev;

mysql :

, , nginx hostnames

docker run -it --rm -p 3308:3306 --name mysql-1 --hostname mysql-1 mysql:latest
docker run -it --rm -p 3308:3306 --name mysql-2 --hostname mysql-2 mysql:latest

1 mysql, ...

:
haproxy :

# nginx
mode tcp
balance roundrobin
server nginx-1 localhost:8081 check port 8081 inter 1000
server nginx-2 localhost:8082 check port 8082 inter 1000
# mysql
# etc

PS: docker-compose, , ... , docker-compose.

+3

All Articles