Docker networking
Your containers are running. So how do they talk to each other, and to you? With Server AI Hub, the Networks tab lists the Docker networks on your DGX Spark.
Chapters
- 0:00Introduction
- 0:06With Server AI Hub: Networks in view
- 0:19What you gain: The benefits
- 0:29The alternative: By hand
- 0:37Where this fits: The AI stack
- 0:40Walls first: Each has its own view
- 0:47Default: The default bridge
- 0:57Better: Make your own
- 1:07Try it: Three commands
- 1:21Getting in: Publishing a port
- 1:39See it: Open it in a browser
- 1:51Two more: Host and none
- 2:02Compose: Names for free
- 2:11Recap: Connected safely
- 2:16Wrap up
Read the transcript
Introduction
Your containers are running. So how do they talk to each other, and to you?
With Server AI Hub: Networks in view
With Server AI Hub, the Networks tab lists the Docker networks on your DGX Spark. Open one to see which containers are on it, and their addresses. Create or remove a network from a button.
What you gain: The benefits
That means you can check how things are connected without a command, spot a container on the wrong network, and be asked before a network is removed.
The alternative: By hand
The other way is by hand. Networks and ports are set with Docker commands. Here's how it works.
Where this fits: The AI stack
Today's block: containers.
Walls first: Each has its own view
Normally, each container gets its own view of the network. Docker networks are how you connect them.
Default: The default bridge
If you don't choose, a container joins the default bridge network. Containers there can reach each other by IP address, but not by name.
Better: Make your own
Make your own network instead. Now containers on it can find each other by name. And containers on separate networks are kept apart.
Try it: Three commands
Type these in a Terminal. First, create a network, start a database on it, then start your app. Here my DB and my app are made-up names, so use your own images. The app can call the database db.
docker network create mynet
docker run -d --network mynet --name db my-db
docker run -d --network mynet my-appGetting in: Publishing a port
To reach a container from outside, you publish a port. This sends port 8080 on the computer to port 80 inside. Careful: by default, other machines that can reach your computer can use it too. To keep it to this computer only, publish it on its local address.
See it: Open it in a browser
Say your app is a web page on port 80. Add this when you start it. Then, on that same computer, open a web browser and go to localhost:8080.
docker run -d -p 127.0.0.1:8080:80 my-appTwo more: Host and none
With host networking, a container shares the computer's own network, so there's no port to publish. With none, it gets no network at all, apart from talking to itself.
Compose: Names for free
Using Docker Compose? It makes a network for your project, and each service can find the others by its service name.
Recap: Connected safely
Name your networks, publish only what you need, and know who can reach it.
Wrap up
Plan your ports with care, and let Server AI Hub show you the result: every network and its containers in view, buttons to change them, and a question before one is removed.
Sources
- docs.docker.com/engine/network
- docs.docker.com/engine/network/drivers/bridge
- docs.docker.com/engine/network/port-publishing
- docs.docker.com/engine/network/drivers/host
- docs.docker.com/engine/network/drivers/none
- docs.docker.com/compose/how-tos/networking
More lessons
- Docker basics 3:24
- Docker intermediate 2:26
- Docker advanced 2:44
- GitHub basics 1:51
- GitHub intermediate 1:57
- GitHub advanced 1:59