I have 2 different component/images and following docker-compose file.
version: '3' services: my_service: image: my_service:latest restart: always environment: - DUMMY=dummy ports: - "8071:8071" command: "" healthcheck: test: ["CMD-SHELL", "[ -f /usr/local/bin ]"] interval: 30s timeout: 30s retries: 3 container_name: my-service-container networks: - my_net my_ui: image: my_ui:latest depends_on: - my_service restart: always ports: - "8080:8080" command: "" networks: - my_net networks: my_net: driver: bridge
"my_ui" component is a ui (angular code) which calls services from "my_service" component.
When I call using the "real" host name (server where all deployment is there) it works i.e.
Hostname (Linux): real.host.name
Docker is installed and running on above host. I run docker-compose up on the above host so my dontainers are up and running.
From another machine or host I call the following via postman, and it works.
(POST request, has raw body as required, etc).
The above call works. However, I want to use the docker service name for such calls so deployment to multiple host/env is smooth.
When I try the below, it does not work:
Failed to load resource: net::ERR_NAME_NOT_RESOLVED
When I go to "my_ui"
docker exec -it rm <container name of my_ui> /bin/bash $ ping my_service
The above works fine i.e. ping is good. However, when I make the http request it does not recognize the "my_service" host.
Can someone help here?
Source: Docker Questions