Loading…
Warp is now open-source Learn more
Loading…
In Docker, a network is a communication mechanism that allows isolated containers to communicate with each other as well as external services located on the same host or distant machines.
The base command for managing Docker networks is the docker network command, which enables developers to create, inspect, connect, disconnect, and remove networks:
$ docker network <subcommand>Where subcommand includes create , inspect , connect , and so on.
If you’re using Warp as your terminal, you can easily retrieve these commands using the Warp AI Command Suggestions feature:

Entering docker network in the AI Command Suggestion will prompt a list of docker commands that can then quickly be inserted into your shell by pressing CMD+ENTER .
To create a new Docker network, you can use the docker network create command as follows:
$ docker network create <network_name>For example, this command will create a new network named my\_network :
$ docker network create my_networkIn Docker, a network driver is a component responsible for determining how containers on a Docker host connect and communicate with each other and with external networks.
Docker supports multiple network drivers, each designed to meet specific use cases:
To create a new Docker network with a specific driver instead of the default bridge driver, you can use the docker network create command with the -d flag (short for --driver ):
$ docker network create -d <driver_type> <network_name>Note that, if the -d flag is not specified, the network driver will default to bridge.
For example, this command will create a new network named my\_new\_bridge using the host driver:
$ docker network create -d host my_new_bridgeTo get the list of existing Docker networks, you can use the docker network ls command:
$ docker network lsFor example:
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
d4fe037a03e3 bridge bridge localTo get detailed information about a Docker network, such as its name, ID, driver type, IP address, associated containers, and more, you can use the docker network inspect command:
$ docker network inspect <network_name>For example, this command will return the detailed information of the network named my\_network :
$ docker network inspect my_networkTo connect a running container to an existing network and enable it to communicate and exchange data with the other containers connected to the same network, you can use the docker network connect command as follows:
$ docker network connect <network_name> <container_id>Note that, by default, Docker automatically assigns an IP address to the container from the subnet of the specified network.
For example, this command connects the container identified by the ID 7783cbb0deaa to the network named my\_network :
$ docker network connect my_network 7783cbb0deaaAlternatively, you can launch a new container and connect it to a network at the same time using the docker run command combined with the --network flag as follows:
$ docker run -it --network my_network busybox:latestTo disconnect a container from a network, you can use the docker network disconnect command as follows:
$ docker network disconnect <network_name> <container_id>For example:
$ docker network disconnect my_network 7783cbb0deaaTo remove an existing Docker network, you can use the docker network rm command as follows:
$ docker network rm <network_name>Note that, if containers are connected to the network you are trying to remove, Docker will prompt you for confirmation before disconnecting these containers and removing the network.
For example:
$ docker network rm my_networkTo free up disk space and resources, you can remove all unused networks that are not connected to any containers (i.e. pruning) using the docker network prune command:
$ docker network pruneThe none network driver is used to create containers without any networking capabilities, which means that they won’t be able to communicate with the external world or with other containers.
This network mode is mostly useful for containers that are used solely for data storage, batch processing jobs, or debugging.
To create a container without any networking capabilities, you can use the --network flag as follows:
$ docker run -it --network none alpine:latestA concise guide to learning Docker using Lazydocker. Highlights Docker’s benefits and takes advantage of Warp's AI features for a quick setup.
Learn how to launch and connect to a containerized SSH server in Docker using password-based authentication and SSH keys.
Learn how to remove a Docker image locally, on a Docker registry, and on Artifactory.
Learn how to override and customize the entrypoint of a Docker container using the docker run command.
Learn how to define and set build-time variables for Docker images using the ARG instruction and the --build-arg flag.
Learn how to start a new Docker container from an image in both the foreground and the background using the docker-run command.
How to gracefully shutdown running containers and forcefully kill unresponsive containers with signals in Docker using the docker-stop and docker-kill commands.
Learn how to set, change and match a docker container hostname.
Learn how define and pass environment variables to Docker containers using an .env file in Docker Compose.
Learn how to write and use .env files in Docker to populate the environment of containers on startup.
Learn how to restart Docker containers automatically with restart policies and manually using the docker restart, docker start, docker stop and docker kill commands.
Start an interactive shell in Docker container
$ docker network <subcommand>$ docker network create <network_name>$ docker network create my_network$ docker network create -d <driver_type> <network_name>$ docker network create -d host my_new_bridge$ docker network ls$ docker network ls
NETWORK ID NAME DRIVER SCOPE
d4fe037a03e3 bridge bridge local$ docker network inspect <network_name>$ docker network inspect my_network$ docker network connect <network_name> <container_id>$ docker network connect my_network 7783cbb0deaa$ docker run -it --network my_network busybox:latest$ docker network disconnect <network_name> <container_id>$ docker network disconnect my_network 7783cbb0deaa$ docker network rm <network_name>$ docker network rm my_network$ docker network prune$ docker run -it --network none alpine:latest