Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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"

services:

 consumer:

   image: employee-consumer

   networks:

     - consumer-producer

   depends_on:

     - producer

 producer:

   image: employee-producer

   ports:

     - "8080:8080"

   networks:

     - consumer-producer

networks:

 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!

28.4k questions

29.7k answers

500 comments

94.6k users

Browse Categories

...