FreeKB - docker network command (connect a container to a network)
Docker - docker network command (connect a container to a network)

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": {


Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments