Docker – Docker Network – Remove, Prune – Learning-Ocean

Docker Network (Remove, Prune)

Docker network remove

We can remove the networks using the docker rm command. It removes one or more networks by name or id. To remove a network, you must first disconnect any containers connected to it.

Syntax

$

docker network rm NETWORK [NETWORK...]

Example

gaurav

@learning

-

ocean:

~

$

docker network ls NETWORK ID     NAME      DRIVER    SCOPE 6c51373f78ac   bridge    bridge    local 3a33f83c3663   host      host      local e4ebd601732c   none      null      local 348f7295d3ca   test      bridge    local gaurav

@learning

-

ocean:

~

$

docker network rm test test gaurav

@learning

-

ocean:

~

$

Docker network prune

Remove all unused networks. Unused networks are those which are not referenced by any containers.

Syntax

$

docker network prune NETWORK [NETWORK...]

Example

gaurav

@learning

-

ocean:

~

$

docker network create test 865536ce95010b33823d80a00c37a6158aa8ac8617a64aa81992a9e82dee3bdb gaurav

@learning

-

ocean:

~

$

docker network create test1 a9eb7bd5cdbde97a7e881a8a0423d32febee73e38b149783e24b4e96c0dabf7b gaurav

@learning

-

ocean:

~

$

docker network ls NETWORK ID     NAME      DRIVER    SCOPE 6c51373f78ac   bridge    bridge    local 3a33f83c3663   host      host      local e4ebd601732c   none      null      local dfe7c45009bd   test      bridge    local d2d0171cf04c   test1     bridge    local gaurav

@learning

-

ocean:

~

$

docker network prune WARNING! This will remove all custom networks

not

used by at least one container. Are you sure you want to continue? [y/N] y Deleted

Networks:

test1 test gaurav

@learning

-

ocean:

~

$

docker network ls NETWORK ID     NAME      DRIVER    SCOPE 6c51373f78ac   bridge    bridge    local 3a33f83c3663   host      host      local e4ebd601732c   none      null      local gaurav

@learning

-

ocean:

~

$