Answer the question
In order to leave comments, you need to log in
How to work with multiple projects in docker?
Good afternoon.
I decided to switch from vagrant to docker. I read a lot of manuals, the essence is the same everywhere - we write the config, then docker-compose build and up and go to localhost: 8080 - everything works there. I tried it - it really works. But here questions arise. I worked with openserver before, then switched to vagrant. I have about 20 projects in the same environment (because they are all on php7.3, mysql 5.7, nginx) In general, there are no differences, so they all worked fine on the same vagrant virtual machine. I really liked the process of writing url => path. As a result, all 20 projects could be opened at the same time - they all worked.
But here I am on docker and I have the same questions:
1) How to make all projects work at the same time?
2) How to give projects not localhost:8080, but a normal url like project.dev?
Something about the docker is the same info everywhere, some stories about the advantage of containers, some "let's run localhost: 8080", and step left and right - I can't find any info ... anyway, I didn't succeed.
Thanks in advance for your replies.
Answer the question
In order to leave comments, you need to log in
all on php7.3, mysql 5.7, nginx
location /project-42 { root /projects/project-42; ... }
### или целый блок
server {
listen 80;
server_name project42.dev;
...
}
nginx:
volumes:
- "/freelance/projects/Project-0/:/var/www/project0"
- "/freelance/projects/Project-42/:/var/www/project42"
# ...
php-fpm:
volumes:
# то же самое сюда
docker-compose.yml
instead of 8080:80
- 80:80
, and in the local hosts file , add 127.0.0.1 project.dev project42.dev
It will be more pleasant to work with so many projects if you pass them all through traefik. Additional 3-4 lines of notifications to the project description in the docker-compose file and everything is seen through one entry point.
You are looking for jwilder/nginx-proxy on the github (for some reason it does not allow you to post a link)
1. If the projects are different, then you will have to resolve external ports 8081:80, 8082:80, if the project is one of several services, you can make 1 proxy with port 80 and redirect to containers with php-fpm
2. In /etc/hosts add your domains on ip 127.0.0.1. Use local instead of dev
And why do you need to work with several projects at the same time, raised the containers through the docker-compose of the site, worked, paid off, switched to another project, raised the network, worked, closed, etc.
The default port and host can be set via variables in docker-compose.yml:
version: '3.4'
services:
app:
build:
context: ..
dockerfile: ./docker/Dockerfile
restart: ${APP_RESTART_MODE:-always}
volumes:
- static:/usr/src/app/static
- ${APP_PUBLIC_DIR:-./data}:/usr/src/app/public:rw
environment:
APP_SERVER_HOSTS: ${APP_SERVER_HOSTS:-www.project.com}
APP_SERVER_PORT: ${APP_SERVER_PORT:-8080}
nginx:
build:
context: .
dockerfile: ./Dockerfile-nginx
restart: ${APP_RESTART_MODE:-always}
environment:
NGINX_HOST: ${APP_SERVER_HOSTS:-www.project.com}
NGINX_PORT: ${APP_SERVER_PORT:-8080}
ports:
- "${APP_SERVER_PORT:-8080}:${APP_SERVER_PORT:-8080}"
volumes:
- static:/usr/src/app/static
- ${APP_PUBLIC_DIR:-./data}:/usr/src/app/public:ro
command: /bin/ash -c "envsubst < /etc/nginx/conf.d/default.conf.tpl > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
depends_on:
- app
links:
- app
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question