Middle
Kuidas ühendada kaks Docker konteinerit samas võrgus ühel hostil?
sobes.tech AI
Vastus AI-lt
To connect two Docker containers on the same host into a network, you need to create a custom Docker network and run the containers in this network. This will allow the containers to communicate with each other by container names.
Example:
- Create the network:
docker network create minu_tīkls
- Run the containers and connect them to the network:
docker run -d --name konteiner1 --network minu_tīkls attēls1
docker run -d --name konteiner2 --network minu_tīkls attēls2
Now the containers can communicate with each other using the names konteiner1 and konteiner2 within the minu_tīkls network.
This is useful for microservices, when internal communication needs to be ensured without exposing ports outward.