Answer the question
In order to leave comments, you need to log in
How to communicate between docker containers?
Hello colleagues.
There are different services, for example, let's take two service-a (php, nginx) and service-b
service-a
version: '3.5'
networks:
main:
driver: bridge
name: main
ipam:
driver: default
config:
- subnet: 172.26.13.0/24
services:
php-service-a:
build:
context: .
dockerfile: docker/php-extended/Dockerfile
args:
ssh_prv_key: ""
volumes:
- ./:/app
- "phpsocket:/var/run"
- ~/.ssh:/root/.ssh
networks:
- main
nginx-service-a:
build:
context: .
dockerfile: docker/nginx/Dockerfile
ports:
- "${NGINX_PORT}:80"
volumes:
- ./:/app
- "phpsocket:/var/run"
depends_on:
- php-service-a
networks:
- main
volumes:
phpsocket:
version: '3.5'
networks:
main:
external:
name: main
services:
service-b:
build:
context: .
dockerfile: docker/golang/local.Dockerfile
working_dir: /go/app
volumes:
- ./:/go/app
ports:
- "${GO_PORT}:8080"
environment:
- DB_USERNAME
- DB_PASSWORD
- DB_HOST
- DB_EXTERNAL_PORT
- DB_DB
networks:
- main
tty: true
Answer the question
In order to leave comments, you need to log in
Only request to host.docker.internal:8027 works. Please explain why? It seems that the request should work by the name of the service inside the container.
There is no need to stuff anything into one docker-compose.yml, everything should work like that.
Docker-compose is just a wrapper around the standard docker api, so it's the same as running containers through docker run.
Why, specifically, it does not work for you, I can’t say for sure.
First look at docker network ls to see if compose creates a network with prefixes/suffixes.
Try to create a network from the outside, and in both files write external.
Well, and also, perhaps it depends on the OS on which you are doing all this. (On a poppy, for example, everything works)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question