I have a docker-compose.yml
file of a project server.It contains a mongo
container, nginx
service and a panel.
I have to containerize my service and the panel for both test and main environements.Firstly I publish on test, afterwards I publish on main.
After the publishing on main nginx
forward requests to test and that is the issue.
Restarting the nginx
fixes the problem, so how can I fix the issue permanantly without restarting nginx
after each publish on the main environement.
docker-compose.yml
:
version: '3.7'
services: main-mongo:
image: mongo:4.2.3
container_name: main-mongo
volumes:
- mongodb:/data/db
- mongoconfig:/data/configdb
main_service:
image: project
container_name: main_service
restart: on-failure
volumes:
- ./views:/project/views
- ./public:/project/public
depends_on:
- main-mongo
test_service:
image: test_project
container_name: test_service
restart: on-failure
volumes:
- ./test_view/views:/project/views
- ./test_view/public:/project/public
environment:
- ENV=test
depends_on:
- main-mongo
test_panel:
image: test_panel
container_name: test_panel
restart: on-failure
environment:
- ENV=test
depends_on:
- main-mongo
main_panel:
image: panel
container_name: main_panel
restart: on-failure
depends_on:
- main-mongo
python_backend_test:
image: python_backend_test
container_name: python_backend_test
restart: on-failure
volumes:
- /tmp:/tmp
nginx:
image: nginx:1.17
container_name: nginx
restart: on-failure
ports:
- 80:80
volumes:
- ./nginx:/etc/nginx/conf.d/
- ./panel_front:/usr/share/panel
depends_on:
- main_panel
- test_panel
- test_service
- main_service
volumes: mongodb: mongoconfig:
nginx.conf
:
server {
listen 80;
listen [::]:80;
server_name domain.com;
location /api {
proxy_pass http://main_panel:3000;
}
location /account {
root /usr/share/panel/live;
try_files $uri $uri/ /index.html;
}
location / {
proxy_pass http://main_service:3000;
}
}
server {
listen 80;
listen [::]:80;
server_name test.domain.com;
location /netflix {
proxy_pass http://python_backend_test:5000;
}
location /api {
proxy_pass http://test_panel:3000;
}
location /account {
alias /usr/share/panel/test/;
try_files $uri $uri/ /index.html;
}
location / {
proxy_pass http://test_service:3000;
}
}
2
Answers
I had same issue.
I solve the problem with creating network for
docker-compose
.Create a network for you project and add all of your containers to that network.
It’s more clear that default network.default network may conflict.