DOCKER · Networking · 8 min

Connect containers without a host port

Use a named internal network and container DNS.

Not completed

Your task

Create the internal practice network, start the web container without publishing a host port, and fetch it by name from a temporary client. Save the response in response.txt.

What you’re aiming for

  • response.txt contains Practice server.
  • The named network is internal.
  • The server has no published host port.

1. Prepare your practice folder

Use a running Docker engine in Linux container mode. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.

Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.

NEW PRACTICE FOLDER
mkdir opsrung-docker-private-network-request && cd opsrung-docker-private-network-request

Run these setup commands in that folder:

SETUP — RUN ONCE
cat > Dockerfile <<'DOCKERFILE'
FROM alpine:3.22
RUN apk add --no-cache busybox-extras
WORKDIR /site
RUN printf 'Practice server\n' > index.html
USER 65534:65534
CMD ["httpd","-f","-p","8080","-h","/site"]
DOCKERFILE
docker build -t opsrung-private-network-request:practice .

Docker may download the official Alpine image and, for the web task, its HTTP package. If an example container name already exists, use a different name consistently. If port 8088 is occupied, choose another free local port.

2. Try the task

Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.

Hint 1

Containers on a user-defined network can resolve each other by name.

Hint 2

The client connects to CONTAINER:8080, not localhost.

Hint 3

Use an internal network and run wget from a temporary container on that same network.

3. Review your result

Use these commands to look at your result and compare it with the goals. The website does not run or verify them.

REVIEW IN YOUR TERMINAL
cat response.txt
docker network inspect opsrung-private-network-request-net --format "{{.Internal}}"
docker port opsrung-private-network-request

What you should see

  • response.txt contains Practice server.
  • The named network is internal.
  • The server has no published host port.

If your result differs: Compare the actual output with each goal. Keep your work inside this exercise’s folder and use only its named resources.

Compare with one possible solution
ONE POSSIBLE SOLUTION
docker network create --internal opsrung-private-network-request-net
docker run -d --name opsrung-private-network-request --network opsrung-private-network-request-net --read-only --cap-drop ALL --security-opt no-new-privileges opsrung-private-network-request:practice
docker run --rm --network opsrung-private-network-request-net --read-only --cap-drop ALL --security-opt no-new-privileges opsrung-private-network-request:practice wget -qO- http://opsrung-private-network-request:8080 > response.txt

Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.

Clean up this exercise

Only remove the example resources you created. Volume cleanup deletes that exercise’s saved sample data. Keep anything you need.

OPTIONAL CLEANUP
docker stop opsrung-private-network-request
docker rm opsrung-private-network-request
docker network rm opsrung-private-network-request-net
docker image rm opsrung-private-network-request:practice

Finished this exercise?

You decide when you’re done. Your choice is saved in this browser, and you can change it later.