Bootstrap FreeKB - Docker - Create a network using the docker network create command
Docker - Create a network using the docker network create command

Updated:   |  Docker articles

This assumes you have installed Docker on Linux and Docker is running. Before creating a docker network, ensure the host Linux operating system has a firewall deamon running, such as firewalld or iptables. The following command creates a docker network named foo-network.

By default, the network will use the bridge driver.

docker network create foo-network

 

Or the -d or --driver option can be used to select a driver, such as overlay.

docker network create --driver overlay foo-network

 

AVOID TROUBLE

When using the docker run command to create and start a container, if you use one of the default Docker networks, or a user defined Docker network that was not created using the --subnet option, you will probably get "user specified IP address is supported only when connecting to networks with user configured subnets" when attempting the docker run command.

For this reason, it almost always makes sense to include the --subnet and --gateway options when creating a network that will be used for static IP addressing.

docker network create --subnet 172.20.0.0/16 --gateway 172.20.0.1 foo-network

 

The docker network ls command can be used to display the docker networks.

docker network ls

 

Which should return something like this.

NETWORK ID     NAME           DRIVER      SCOPE
233g3acb112a   foo-network    bridge      local

 

The docker volume inspect command can be used to display the configuration of the network.

docker network inspect foo-network

 

Which should return JSON something like this.

[
 {
  "Name":"foo-network",
  "Id":"xxxxxxxxxxxxxxxxxxxxxxxxxx",
  "Created":"yyyy-mm-ddThh:mm:ss.sss",
  "Scope":"local",
  "Driver":"bridge",
  "EnableIPv6": false,
  "IPAM" {
    "Driver":"default",
    "Options" {},
    "Config": [
      {
        "Subnet": "172.19.0.0/16",
        "Gateway": "172.19.0.1"
      }
    ]
  },
  "Internal": false,
  "Attachable": false,
  "Containers": {},
  "Options": {},
  "Labels": {}
 }
]

 

When using the docker run command to install an image, the --network option can be used to configure the image to use the network, like this.

docker run --network=foo-network bar:latest

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter d31c0e in the box below so that we can be sure you are a human.