DOCKER · Networking · 8 min
Publish a port on localhost only
Expose a practice web server without binding it to every interface.
Not completedYour task
Run opsrung-web:practice as opsrung-web and map host port 8088 to container port 8080. Bind only to 127.0.0.1. If 8088 is occupied, choose another free local port.
What you’re aiming for
- The named container is running the image you built.
- Container port 8080 is mapped to host port 8088, or your chosen free port.
- The host binding is 127.0.0.1.
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.
mkdir opsrung-docker-local-port && cd opsrung-docker-local-port
Run these setup commands in that folder:
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-web: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
The Dockerfile from setup creates a small web server listening on port 8080.
Hint 2
A port mapping can include a host address before the host port.
Hint 3
Use -p 127.0.0.1:8088:8080, substituting your chosen host port if needed.
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.
docker port opsrung-web curl http://127.0.0.1:8088
What you should see
- docker port opsrung-web shows container port 8080 mapped to 127.0.0.1:8088, or your chosen free host port.
- curl to that local address prints Practice server.
If your result differs: A binding of 0.0.0.0 does not meet this task. Use 127.0.0.1 explicitly, and use your chosen host port in both the mapping and curl command.
Compare with one possible solution
docker run -d --name opsrung-web -p 127.0.0.1:8088:8080 --read-only --cap-drop ALL --security-opt no-new-privileges opsrung-web:practice docker port opsrung-web
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.
docker stop opsrung-web docker rm opsrung-web docker image rm opsrung-web:practice
Finished this exercise?
You decide when you’re done. Your choice is saved in this browser, and you can change it later.