I would like to configure my machine in such a way that i can easily work on different projects running on different versions of php as well as mysql database. My approach is to use centralized containers.
I have pulled following images.
REPOSITORY TAG IMAGE ID CREATED SIZE bitnami/codeigniter 3 25da0598c415 2 hours ago 287MB php 7.1-apache 3aaef27a36f8 7 days ago 402MB php 7.2-apache 071b437a2194 7 days ago 410MB phpmyadmin/phpmyadmin latest 91490af22618 10 days ago 454MB php 7.3-apache 5af347316d4b 2 weeks ago 410MB mysql 5.6 b3983abaa3fe 2 weeks ago 302MB mysql 5.7 cd3ed0dfff7e 2 weeks ago 437MB mysql 8.0 c8ee894bd2bd 2 weeks ago 456MB mysql latest c8ee894bd2bd 2 weeks ago 456MB php 5.6-apache 24c791995c1e 9 months ago 355MB php 7.0-apache aa67a9c9814f 10 months ago 368MB
For the practice i have created different containers using above images
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e316ebbabad2 mysql:8.0 "docker-entrypoint.s…" 7 days ago Up 11 minutes 33060/tcp, 0.0.0.0:3308->3306/tcp mysql80 da8811e5b472 phpmyadmin/phpmyadmin "/docker-entrypoint.…" 7 days ago Up 11 minutes 0.0.0.0:8003->80/tcp pma80 3518f98e9fe7 phpmyadmin/phpmyadmin "/docker-entrypoint.…" 7 days ago Up 10 minutes 0.0.0.0:8002->80/tcp pma57 e3dbe9ec50b8 mysql:5.7 "docker-entrypoint.s…" 7 days ago Up 10 minutes 33060/tcp, 0.0.0.0:3307->3306/tcp mysql57 f0c2e8058b6c phpmyadmin/phpmyadmin:latest "/docker-entrypoint.…" 7 days ago Up 10 minutes 0.0.0.0:8001->80/tcp dbui56 b6cb467b7365 mysql:5.6 "docker-entrypoint.s…" 7 days ago Up 10 minutes 0.0.0.0:3306->3306/tcp
Every container is mapped to different ports:
Let’s say i have a project A & B, which i want to run using php7.2 and mysql5.7 but i dont want to create a separate database containers for each of them, instead i would like to use the existing mysql5.7 container which maps to
CONTAINER ID IMAGE PORTS NAMES e3dbe9ec50b8 mysql:5.7 33060/tcp, 0.0.0.0:3307->3306/tcp mysql57
Is it possible to link a single running container to different containers ? If yes then how ?
I would like to know whether my approach is correct or wrong ? If wrong then why ?, If i am working on 5 different projects each having its own database container as well as phpmyadmin wouldn’t it be the waste of memory and space. I am not sure what i actually want is possible or not, read many articles but still confused and couldn’t pin point from where i should start. Currently i am using different versions of php-fpm with apache on my machine using Ubuntu 18 LTS.