0
0
Dockerdevops~10 mins

Port mapping with -p flag in Docker - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the command to map port 8080 on the host to port 80 in the container.

Docker
docker run -d [1] nginx
Drag options to blanks, or click blank then click option'
A-P 8080:80
B-e 8080:80
C-p 8080:80
D-v 8080:80
Attempts:
3 left
💡 Hint
Common Mistakes
Using -v which is for volumes, not ports.
Using uppercase -P which maps random ports, not specific ones.
2fill in blank
medium

Complete the command to map host port 5000 to container port 5000.

Docker
docker run -d [1] myapp
Drag options to blanks, or click blank then click option'
A-P
B-v 5000:5000
C-e 5000:5000
D-p 5000:5000
Attempts:
3 left
💡 Hint
Common Mistakes
Using -P which maps random ports instead of specific ones.
Using -v which is for volumes, not ports.
3fill in blank
hard

Fix the error in the command to map host port 3000 to container port 3000.

Docker
docker run -d [1] 3000:3000 myapp
Drag options to blanks, or click blank then click option'
A-p
B-P
C-v
D-e
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase -P which maps random ports.
Using -v which is for volumes.
Not adding a space after the flag.
4fill in blank
hard

Fill both blanks to map host port 8081 to container port 80 and host port 443 to container port 443.

Docker
docker run -d [1] [2] nginx
Drag options to blanks, or click blank then click option'
A-p 8081:80
B-v 8081:80
C-p 443:443
D-e 443:443
Attempts:
3 left
💡 Hint
Common Mistakes
Using -v or -e flags which are not for port mapping.
Using only one -p flag for multiple ports without repeating.
5fill in blank
hard

Fill all three blanks to run a container mapping host ports 5000 and 6000 to container ports 5000 and 6000, and set environment variable ENV=prod.

Docker
docker run -d [1] [2] [3] ENV=prod myapp
Drag options to blanks, or click blank then click option'
A-p 5000:5000
B-p 6000:6000
C-e
D-v
Attempts:
3 left
💡 Hint
Common Mistakes
Using -v instead of -p for ports.
Not using -e for environment variables.
Trying to map multiple ports with one -p flag.