I am trying to create multiple containers with my existing Magento project.
Task # 1) I have successfully moved the existing project to Docker by following markshust/docker-magento . Everything working perfectly fine as expected. But this is only for moving single Magento instance to Docker
Task # 2) I am trying to similarly create multiple instances of the same existing Magento project on Docker
I tried to create 2 different YMLs with different --project-name
(to differentiate between containers). Followed same steps as for Task # 1 and updated external ports in the second YML. But unfortunately I am not able to run any of the containers now. None working!
When I am trying to access first Magento container eg https://example.com:444/ it add errors in system.log
and strangely, the same error is being logged inside my second docker container's system.log
I suspect that volumes are creating problems in my case (as volumes path are same in both YMLs) but I am not able to figure out the exact problem here. Adding both YMLs below
docker-compose.yml (Placed at docker root directory)
version: "3"
services:
app:
image: markoshust/magento-nginx:1.18-5
ports:
- "81:8000"
- "444:8443"
depends_on:
- "db"
volumes: &appvolumes
- ~/.composer:/var/www/.composer:cached
- ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
- ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
- appdata:/var/www/html
- sockdata:/sock
- ssldata:/etc/nginx/certs
networks:
- customNetwork
phpfpm:
image: markoshust/magento-php:7.4-fpm-11
volumes: *appvolumes
env_file: env/phpfpm.env
networks:
- customNetwork
db:
image: mariadb:10.4
restart: on-failure
command: --max_allowed_packet=256M
ports:
- "3307:3306"
env_file: env/db.env
volumes:
- dbdata:/var/lib/mysql
networks:
- customNetwork
redis:
image: redis:5.0-alpine
ports:
- "6379:6379"
networks:
- customNetwork
elasticsearch:
image: markoshust/magento-elasticsearch:7.9.3-1
ports:
- "9201:9200"
- "9301:9300"
environment:
- "discovery.type=single-node"
## Set custom heap size to avoid memory errors
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
## Avoid test failures due to small disks
## More info at https://github.com/markshust/docker-magento/issues/488
- "cluster.routing.allocation.disk.threshold_enabled=false"
- "index.blocks.read_only_allow_delete"
networks:
- customNetwork
volumes:
appdata:
dbdata:
sockdata:
ssldata:
networks:
customNetwork:
docker-compose-second.yml (Placed at docker root directory)
version: "3"
services:
app:
image: markoshust/magento-nginx:1.18-5
ports:
- "82:8000"
- "445:8443"
depends_on:
- "db"
volumes: &appvolumes
- ~/.composer:/var/www/.composer:cached
- ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
- ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
- appdata:/var/www/html
- sockdata:/sock
- ssldata:/etc/nginx/certs
networks:
- customNetworkM2
phpfpm:
image: markoshust/magento-php:7.4-fpm-11
volumes: *appvolumes
env_file: env/phpfpm.env
networks:
- customNetworkM2
db:
image: mariadb:10.4
restart: on-failure
command: --max_allowed_packet=256M
ports:
- "3308:3306"
env_file: env/db.env
networks:
- customNetworkM2
redis:
image: redis:5.0-alpine
ports:
- "6381:6379"
networks:
- customNetworkM2
elasticsearch:
image: markoshust/magento-elasticsearch:7.9.3-1
ports:
- "9202:9200"
- "9302:9300"
environment:
- "discovery.type=single-node"
## Set custom heap size to avoid memory errors
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
## Avoid test failures due to small disks
## More info at https://github.com/markshust/docker-magento/issues/488
- "cluster.routing.allocation.disk.threshold_enabled=false"
- "index.blocks.read_only_allow_delete"
networks:
- customNetworkM2
volumes:
appdata:
dbdata:
rabbitmqdata:
sockdata:
ssldata:
networks:
customNetworkM2:
db.env (Placed at [docker root]/env directory)
MYSQL_HOST=db
MYSQL_ROOT_PASSWORD=magento
MYSQL_DATABASE=magento
MYSQL_USER=root
MYSQL_PASSWORD=magento
MYSQL_INTEGRATION_ROOT_PASSWORD=magento
MYSQL_INTEGRATION_DATABASE=magento_integration_tests
MYSQL_INTEGRATION_USER=root
MYSQL_INTEGRATION_PASSWORD=magento
MYSQL_INTEGRATION_HOST=db
I am new to Docker. Need some help. PS I am using docker & docker-compose on Ubuntu 18.04 and Magento 2.4.3-P1
I think looking at examples that are easy to understand could give you the best picture.
What you want to do is perfectly valid, an image should be anything you need to run, without the configuration.
To generate the configuration, you either:
a) volume mounts
use volumes and mount the file during container start docker run -v my.ini:/etc/mysql/my.ini percona (and similar with docker-compose)
b) entry-point based configuration (generation)
c) Derived images
Maybe for "completeness", the image-derive strategy, so you have your base image called "myapp" and for the installation X you create a new image
from myapp
COPY my.ini /etc/mysql/my.ini
COPY application.yml /var/app/config/application.yml
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.