Fairly new to docker, but I have 2 projects - project-a and project-b, I would like to develop on them both locally using docker, with an nginx-proxy container to route between them.
So far I have:
1) Create a new docker network called 'my-network' in bridge mode. 2) Started up nginx-proxy container, and configured dnsmasq to route '.dev' domains to individual containers (this all works fine) 3) Starting up project-a with the following docker-compose.yml file
version: '3.2'
services:
web:
image: brettt89/silverstripe-web
working_dir: /var/www
restart: unless-stopped
volumes:
- .:/var/www/html
environment:
- VIRTUAL_HOST=project-a.dev
db:
image: mysql
volumes:
- db-data:/var/lib/mysql
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: password
volumes:
db-data:
networks:
default:
external:
name: my-network
This all works as expected with nginx-proxy routing requests for project-a.dev through to this container. MySQL queries work as expected.
However, once I start project-b with the same docker-compose file (except changing the VIRTUAL_HOST env variable to project-b.dev) the problems begin. I can successfully navigate to project-b.dev, however I get intermittent database connection errors across page loads and refreshes - the same errors also start to occur on project-a.dev
Does anyone have any ideas what I'm doing wrong?
As you use the same docker compose, you have 2 database containers, 1 for each project. But they use the same volume. I think it can be a problem. Try to modify the volume name for tour project B (db-data-b for example).
*EDIT for the good answer: * Try not to use the bridged network or inspect containers to avoid IP conflicts.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.