I am trying to set up a docker-compose build such that an admin can create a number of health clinics which each have their own LAMP stack, so one server can host many databases and apaches etc.
My current compose-yml file is :
version: '3'
services:
web:
build:
context: ./www
image: php7.2-apache
restart: always
environment:
- ALLOW_OVERRIDE=true
ports:
- "8080:80"
links:
- db
volumes:
- ./www/html:/var/www/html/
container_name: ${CLINIC_NAME}_WEB
hostname: WEB
networks:
redis:
aliases:
- WEB
db:
build:
context: ./db
image: mariadb
restart: always
volumes:
- ./db/mysql:/var/lib/mysql
- ./db/seed:/var/seed
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: admin
MYSQL_PASSWORD: test
MYSQL_DATABASE: database
ports:
- "8888:3306"
container_name: ${CLINIC_NAME}_DB
hostname: DB
networks:
redis:
aliases:
- DB
networks:
redis:
With a .env file that has CLINIC_NAME and very simple dockerfiles for now, eg.
FROM php:7.2-apache
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
I run docker-compose up -d
in original location everything works well
My issue is when I copy this repo over in order to create a new ‘clinic’, i just change the clinic name in the env file and ports and run docker-compose up -d
, the result is my original containers are replaced by the new ones.
If I try to fix this by specificing project name, ie docker-compse -p name up -d
, then I get 4 containers up and running as expected, but it seems as though the cache for images is not used and docker makes new images.
REPOSITORY TAG IMAGE ID CREATED SIZE
backend_web latest c8da1affae90 35 minutes ago 414MB
callum_web latest c8da1affae90 35 minutes ago 414MB
php7.2-apache latest c8da1affae90 35 minutes ago 414MB
php 7.2-apache 512cfa938317 12 days ago 414MB
callum_db latest 99c1098d5884 2 weeks ago 355MB
mariadb latest 99c1098d5884 2 weeks ago 355MB
backend_db latest 99c1098d5884 2 weeks ago 355MB
I would like to make sure the old images are reused while still having extra containers running.
Thanks!