115k views
5 votes
How to create network in docker compose

1 Answer

1 vote

Final answer:

To create a network in Docker Compose, define networks in the docker-compose.yml file, specify the network settings, and associate services with the network using the networks tag.

Step-by-step explanation:

Creating a Network in Docker Compose

To create a network in Docker Compose, you will need to define it in a docker-compose.yml file. Here's a step-by-step explanation:

  1. Create a docker-compose.yml file if you haven't already.
  2. Under the services section, define your services.
  3. Add a networks section at the bottom of the file.
  4. Specify the network name and additional settings if necessary.
  5. Link the services to the network by adding a networks tag under each service.

Here's an example snippet:

version: '3'
services:
webapp:
image: my-webapp
networks:
- mynetwork
networks:
mynetwork:
driver: bridge

This docker-compose file snippet defines a bridge network named mynetwork and associates the webapp service with it.

User Jonathan Brown
by
8.6k points

Related questions

1 answer
4 votes
229k views
asked Sep 21, 2024 67.5k views
Jigme asked Sep 21, 2024
by Jigme
8.0k points
1 answer
5 votes
67.5k views