How one Docker container can call another Docker container
I have two Docker containers
- Web interface
- Console application calling the web API
Now, on my local webserver, the api is localhost, and in the console app, there is no problem calling the API. However, I have no idea when these two things are Dockerized, how can I make the Dockerized API available to the Url Dockerized app to the docker console app?
I don't think I need Docker Compose because I am passing the API URL as an API argument, so I just need to make sure the URL Dockerized API's
is availableDockerized Console
Any ideas?
source to share
The problem can be solved easily if you use the layout function. With compose, you just create one config file ( docker-compose.yml
) like this:
version: '3'
services:
db:
image: postgres
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
To run it, just call it up
like this:
docker-compose up
This is the best way to get your entire stack running, so check this link: https://docs.docker.com/compose/
Success!
source to share
The idea is to not pass the url but the hostname of the other container you want to call.
See Networking
By default, Compose sets up one network for your application. Each container for a service joins the network by default and is accessible to and discoverable by other containers on that network by a hostname that is identical to the container name.
This will replace the deprecated --link
version .
And if your containers are not running on a single Docker node, Docker Swarm Mode , this will detect detection across multiple nodes.
source to share