Docker Networking
Connect containers with user-defined networks and DNS names.
- docker network
- container DNS
- bridge network
- expose port
- connect containers
Docker Networking
Connect containers with user-defined networks and DNS names.
Commands
| Command | What it does |
|---|---|
docker network create appnet | Create an isolated network |
docker network ls | List networks |
docker run -d --net appnet --name api app:v1 | Attach a container to a network |
docker run -d --net appnet --name web -e API=http://api:8080 nginx | Reach api by DNS name |
docker network inspect appnet | See attached containers and IPs |
Example
docker network create appnet
docker run -d --net appnet --name api app:v1
docker run -d --net appnet --name web nginx:1.27
FAQ
How do containers resolve each other?
On a user-defined network Docker embeds DNS: container names resolve automatically; the default bridge network lacks this.
How do I expose a port only to localhost?
Publish as -p 127.0.0.1:8080:80 so the port never binds to all interfaces.
Частые вопросы
How do containers resolve each other?
On a user-defined network Docker embeds DNS: container names resolve automatically; the default bridge network lacks this.
How do I expose a port only to localhost?
Publish as -p 127.0.0.1:8080:80 so the port never binds to all interfaces.
Docker
Docker Install and Setup
Verify the Docker engine, configure context, and check versions.
Docker Images
Pull, list, tag, inspect, and remove images confidently.
Docker Containers
Run, list, stop, and clean up containers in daily work.
Docker Run Options
The flags that matter: detach, ports, env, volumes, limits.