As per docker link docs I can only --link to one (already running) container to access internal ports of that container.
How can I link one container to 2 or more other containers? (MongoDB and another web service in my case.)
(Right now I am exposing ports of second container to host and then accessing via host:port, also possible workaround might be Let two Containers getting linked to eachother .)
For an easy solution you could use Docker-compose . in you compose file (docker-compose. yml) use the option links Link to containers in another service. Either specify both the service name and a link alias (SERVICE:ALIAS), or just the service name.
If you are running more than one container, you can let your containers communicate with each other by attaching them to the same network. Docker creates virtual networks which let your containers talk to each other. In a network, a container has an IP address, and optionally a hostname.
Container-defined Networking: A container can share the address and network configuration of another container. This enables process isolation between containers, where each container runs one service but where services can still communicate with one another on 127.0.
The docker-compose. yml file allows you to configure and document all your application's service dependencies (other services, cache, databases, queues, etc.). Using the docker-compose CLI command, you can create and start one or more containers for each dependency with a single command (docker-compose up).
docker run -d --link node1:node1 --link node2:node2 --link node3:node3 -p hostport:containerport your-image
I run the command above and it works.
Alternatively, you can turn on inter-container communication by adding --icc=true to the docker daemon's command-line, and you won't have to link the containers, just access them using the Docker Host's IP address and the containers' published ports.
Docker Networking
For an easy solution you could use Docker-compose
. in you compose file (docker-compose.yml) use the option links
Link to containers in another service. Either specify both the service name and a link alias (SERVICE:ALIAS), or just the service name.
container_name:
links:
- node1
- node2
- node3:alias3
- noden
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With