How do you create a custom network and configure a Docker Compose service to use this network?

Experience Level: Junior
Tags: Docker Compose

Answer

Add networks block to the root level of the Docker Compose file together with a network name.
Add networks block to the service and add a network-name to it.
The file should look similar to this:

version: "3.4"
services:
  my-service:
    image: busybox
    networks:
      - my-network
networks:
  my-network:
    name: my-network

Comments

No Comments Yet.
Be the first to tell us what you think.
Docker Compose
Docker Compose

Are you learning Docker Compose ? Try our test we designed to help you progress faster.

Test yourself