Bootstrap FreeKB - Docker - connect a container to a network using the docker network command
Docker - connect a container to a network using the docker network command

Updated:   |  Docker articles

This assumes you have installed Docker on Linux and Docker is running

Let's say you've created a network named my-network and that you've created a container named my-container. The docker inspect command can be used to determine the network(s) the container is using.

docker inspect my-container

 

In this example, my-container is using one network (bridge).

"Networks": {
  "bridge": {

 

The docker network connect command can be used to connect a docker container to another docker network. In this example, my-container is connected to my-network.

docker network connect my-network my-container

 

Reissuing the docker inspect command should now show that my-container is connected to bridge and my-network.

"Networks": {
  "bridge": {
  . . .
  "my-network": {

 

The docker network disconnect command can be used to disconnect a docker container from a docker network. In this example, my-container is disconnected from bridge.

docker network disconnect bridge my-container

 

Reissuing the docker inspect command should now show that my-container is connected to only my-network.

"Networks": {
  "my-network": {



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 03987e in the box below so that we can be sure you are a human.