Hi guys,
I have some problem when 2 container from different container are call through curl
Like test-2.local call to test-1.local.
It always throw this error
cURL error 7: Failed to connect to test-1.local port 80: Connection refused (see libcurl - Error Codes) for http://test-1.local/api/test
This is test-1.local docker-compose
version: '3.5'
services:
php_test_1:
container_name: php_test_1
build:
context: .
dockerfile: ./Dockerfile
# image: digitalocean.com/php
restart: unless-stopped
environment:
# SERVICE_NAME: app
# SERVICE_TAGS: dev
- PHP_ENABLE_XDEBUG=true
- 'XDEBUG_CONFIG=remote_host=172.40.0.1 remote_autostart=1 remote_mode=req'
volumes:
- ./../source:/var/www
- ./config/php/local.ini:/usr/local/etc/php/conf.d/local.ini
- ./config/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
working_dir: /var/www
networks:
- test_1
# Nginx Service
nginx_test_1:
container_name: nginx_test_1
image: nginx:alpine
restart: unless-stopped
ports:
- "80"
- "443"
volumes:
- ./../source:/var/www
- ./config/nginx/conf.d/:/etc/nginx/conf.d/
- ./config/nginx/log/error.log:/var/log/nginx/error.log
- ./config/nginx/log/access.log:/var/log/nginx/access.log
labels:
- "traefik.backend=php_test_1"
- "traefik.docker.network=reverse-proxy"
- "traefik.frontend.rule=Host:test-1.local"
- "traefik.enable=true"
- "traefik.port=80"
- "traefik.http.routers.nginx_test_1.rule=Host(`test-1.local`)"
networks:
- reverse-proxy
- test_1
# MySQL Service
mysql_test_1:
container_name: mysql_test_1
image: mysql:5.7.22
restart: unless-stopped
ports:
- "3306"
environment:
MYSQL_DATABASE: test_1
MYSQL_ROOT_PASSWORD: root
SERVICE_TAGS: dev
SERVICE_NAME: mysql
MYSQL_USER: admin
MYSQL_PASSWORD: 123456
volumes:
- mysqldata:/var/lib/mysql
- ./config/mysql/my.cnf:/etc/mysql/my.cnf
- ./backup/sql/mysql:/home/sqlfiles
networks:
- test_1
adminer_test_1:
container_name: adminer_test_1
image: adminer
restart: unless-stopped
ports:
- 8081:8080
networks:
- test_1
# Docker Networks
networks:
reverse-proxy:
external: true
test_1:
name: test_1
# Docker volume
volumes:
mysqldata:
name: mysqldata_test_1
driver: local
This is test-2.local docker-compose
version: '3.5'
services:
php_test_2:
container_name: php_test_2
build:
context: .
dockerfile: ./Dockerfile
# image: digitalocean.com/php
restart: unless-stopped
environment:
# SERVICE_NAME: app
# SERVICE_TAGS: dev
- PHP_ENABLE_XDEBUG=true
- 'XDEBUG_CONFIG=remote_host=172.40.0.1 remote_autostart=1 remote_mode=req'
volumes:
- ./../source:/var/www
- ./config/php/local.ini:/usr/local/etc/php/conf.d/local.ini
- ./config/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
working_dir: /var/www
networks:
- test_2
# Nginx Service
nginx_test_2:
container_name: nginx_test_2
image: nginx:alpine
restart: unless-stopped
ports:
- "80"
- "443"
volumes:
- ./../source:/var/www
- ./config/nginx/conf.d/:/etc/nginx/conf.d/
- ./config/nginx/log/error.log:/var/log/nginx/error.log
- ./config/nginx/log/access.log:/var/log/nginx/access.log
labels:
- "traefik.backend=php_test_2"
- "traefik.docker.network=reverse-proxy"
- "traefik.frontend.rule=Host:test-2.local"
- "traefik.enable=true"
- "traefik.port=80"
- "traefik.http.routers.nginx_test_2.rule=Host(`test-2.local`)"
networks:
- reverse-proxy
- test_2
# MySQL Service
mysql_test_2:
container_name: mysql_test_2
image: mysql:5.7.22
restart: unless-stopped
ports:
- "3306"
environment:
MYSQL_DATABASE: test_2
MYSQL_ROOT_PASSWORD: root
SERVICE_TAGS: dev
SERVICE_NAME: mysql
MYSQL_USER: admin
MYSQL_PASSWORD: 123456
volumes:
- mysqldata:/var/lib/mysql
- ./config/mysql/my.cnf:/etc/mysql/my.cnf
- ./backup/sql/mysql:/home/sqlfiles
networks:
- test_2
adminer_test_2:
container_name: adminer_test_2
image: adminer
restart: unless-stopped
ports:
- 8081:8080
networks:
- test_2
# Docker Networks
networks:
reverse-proxy:
external: true
test_2:
name: test_2
# Docker volume
volumes:
mysqldata:
name: mysqldata_test_2
driver: local
This is my traefik docker-compose
version: '3.5'
services:
traefik:
image: traefik:1.7
restart: unless-stopped
command:
- --api
- --docker
- --docker.domain=traefik.local
- --docker.exposedByDefault=false
volumes:
- /var/run/docker.sock:/var/run/docker.sock
# - ./config/traefik.toml:/traefik.toml
# - ./config/acme.json:/acme.json
ports:
- 80:80
- 443:443
- 8080:8080
networks:
- reverse-proxy
networks:
reverse-proxy:
name: reverse-proxy
This is my /etc/hosts
# Domain for docker
127.0.0.1 test-1.local
127.0.0.1 test-2.local
I really hope someone can help me getting this to work!
Thanks a lot, best,
Minh