Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (47.6k points)

How do I link containers in a docker compose file (docker-compose.yml)?

1 Answer

0 votes
by (106k points)

Use the below-mentioned steps to link containers in a docker-compose file:-

  • Firstly, create a custom Docker network named consumer-producer network.

  • After that start container named producer using image employee-producer and the custom network consumer-producer.

  • Lastly, start a container named consumer using image employee-consumer and the custom network consumer-producer.

All the above steps can be automated using docker-compose. The compose file will be as follows:- 

version: "3"



   image: employee-consumer


     - consumer-producer


     - producer


   image: employee-producer


     - "8080:8080"


     - consumer-producer



If you want to learn Docker then I would suggest you must take up the following Docker Training Course. If you are more into reading stuff then you can read the following Docker tutorial. Here is a video tutorial regarding Docker which you must watch to learn all the basics of it.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers


104k users

Browse Categories