I am using Docker compose to run nginx+php+mysql environment,OS is centos 7.2, question is about mutiple sub-website on one host:
For example:
There is one host,two projects will run on this host,
named project-a and project-b,
two different docker-compose.yml exsist in project-a and project-b.
Question:
When executing docker-compose up in project-a and project-b,does nginx+php+mysql environment run two or one? If two, a lot of space is occupied ,how to solve this problem?
version: '2' services: nginx: container_name: nginx image: nginx ports: - 80:80 - 443:443 links: - php env_file: - ./.env working_dir: /usr/share/nginx/html # should be `/usr/share/nginx/html/project-a` and `/usr/share/nginx/html/project-b` here? volumes: - ~/docker/nginx/default.conf:/etc/nginx/conf.d/default.conf - ~/docker/nginx/nginx.conf:/etc/nginx/nginx.conf - ~/docker/www:/usr/share/nginx/html php: container_name: php image: fpm links: - mariadb - redis env_file: - ./.env volumes: - ~/docker/www:/usr/share/nginx/html mariadb: container_name: mariadb image: mariadb env_file: - ./.env volumes: - ~/opt/data/mysql:/var/lib/mysql redis: container_name: redis image: redis .env:
project-a and project-bhave different DB_DATABASE and APP_KEY,other items are the same.
APP_ENV=local APP_DEBUG=true APP_KEY=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # Here different. DB_HOST=laravel.dev DB_DATABASE=project-a # Here different. DB_USERNAME=root DB_PASSWORD= CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync REDIS_HOST=laravel.dev REDIS_PASSWORD=null REDIS_PORT=6379 MAIL_DRIVER=smtp MAIL_HOST=mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null Project files:
project-a and project-b have the same catalog.
urls:
project-a:aaa.xxxxxx.com
project-b:bbb.xxxxxx.com
Project folders:
project-a:~/docker/www/project-a
project-b:~/docker/www/project-b
Subsidiary question:
1、Should working_dir be /usr/share/nginx/html/project-name or /usr/share/nginx/html in docker-compose.yml file?
2、If working_dir is /usr/share/nginx/html,I think docker-compose.yml files have the same content in project-a and project-b,right?Is there any other items to be modified?
3、How to merge the compose file into one?
Add2:
project-common: docker-compose.yml
version: '2' services: nginx: container_name: nginx image: nginx php: container_name: php image: fpm mariadb: container_name: mariadb image: mariadb redis: container_name: redis image: redis project-a: docker-compose.yml,and project-b is the same except project name.
version: '2' services: nginx: external_links: - project-common:nginx ports: - 80:80 - 443:443 links: - php env_file: - ./.env working_dir: /usr/share/nginx/html/project-a volumes: - ~/docker/nginx/default.conf:/etc/nginx/conf.d/default.conf - ~/docker/nginx/nginx.conf:/etc/nginx/nginx.conf - ~/docker/www/project-a:/usr/share/nginx/html/project-a php: external_links: - project-common:php links: - mariadb - redis env_file: - ./.env volumes: - ~/docker/www:/usr/share/nginx/html/project-a mariadb: external_links: - project-common:mariadb env_file: - ./.env volumes: - ~/opt/data/mysql:/var/lib/mysql redis: external_links: - project-common:redis 2 Answers
Answers 1
You don't need to run nginx and php-fpm in different containers. (if your projects share same php version)
You run fpm as a service and in the same container run docker in daemon-mode-off.
Then you go to nginx config and setup multiple subdomains.
Then setup data-volumes / shared folders according to your subdomain setup.
So you have single nginx/fpm instance which serves multple projects, and some other database/service containers
Answers 2
I agree with strangeqargo, you need only one container on which you can mount 2 volumes..
If the 2 projects use the same PHP and MariaDB version, just configure them correctly to use different databases but on the same container
0 comments:
Post a Comment