I have 3 images (todofront, todoback, and todotests), and I use docker-compose to orchestrate these images by creating the containers.
Docker-compose:
version: '3'
services:
todotests:
image: todotests
container_name: todotests
environment:
- FRONT_HOST=todofront
restart: always
depends_on:
- todoback
- todofront
todofront:
image: todofrontend
container_name: todofront
ports:
- 3000:3000
environment:
- REACT_APP_API_HOST=todoback
restart: always
depends_on:
- todoback
todoback:
image: todobackend
container_name: todoback
restart: always
ports:
- 3001:3001
In todofront, I use the environment variable REACT_APP_API_HOST with the value 'todoback'. However, this way there is no communication between the front and the back. But when I change the value 'todoback' to 'localhost', then the application works. Is it not possible to use the container name, or is something missing?
To launching containers I use: docker-compose up -d
System: Ubuntu 20.04.6 LTS
image 1:
image 2:
image 3:
In image1, the containers are able to communicate with each other. In image2, I can access the 'todoback' container using 'localhost', but not using 'todoback' which is the container's name.
On image3 I can also access the container using its IP address.