0
0
Dockerdevops~20 mins

Running containers in detached mode in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Detached Mode Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of running a container with detached mode?
You run the command docker run -d nginx. What will the output be?
Docker
docker run -d nginx
AA long container ID string is printed
BThe nginx welcome page HTML is printed
CAn error message about missing image is shown
DThe container logs start streaming in the terminal
Attempts:
2 left
💡 Hint
Detached mode runs the container in the background and prints the container ID.
🧠 Conceptual
intermediate
2:00remaining
Why use detached mode when running containers?
Which reason best explains why detached mode (-d) is used when running Docker containers?
ATo run the container in the background so the terminal is free for other commands
BTo automatically remove the container after it stops
CTo limit the container's CPU usage
DTo run the container with interactive shell access
Attempts:
2 left
💡 Hint
Detached mode frees up your terminal by running the container in the background.
Troubleshoot
advanced
2:00remaining
Why does docker run -d fail with 'no tty present' error?
You run docker run -d -it ubuntu but get an error: 'the input device is not a TTY'. What is the cause?
AThe Ubuntu image is missing from local cache
BUsing both -d (detached) and -t (allocate tty) together causes conflict
CThe Docker daemon is not running
DThe container port is already in use
Attempts:
2 left
💡 Hint
Detached mode means no terminal attached, but -t requests a terminal.
🔀 Workflow
advanced
3:00remaining
What is the correct sequence to run a container detached and then view its logs?
Arrange the commands in the correct order to run an nginx container detached and then see its logs.
A3,1,2,4
B2,1,3,4
C1,2,3,4
D1,3,2,4
Attempts:
2 left
💡 Hint
You must run the container first, check it's running, then view logs, then stop it.
Best Practice
expert
2:30remaining
Which command correctly runs a container detached with port mapping and environment variable?
You want to run a container detached, map port 8080 on host to 80 in container, and set ENV VAR=prod. Which command is correct?
Adocker run --detach -p 80:8080 -e ENV=prod nginx
Bdocker run -p 8080:80 -d -env ENV=prod nginx
Cdocker run -d -p 8080:80 -e ENV=prod nginx
Ddocker run -d -p 80:8080 --env ENV prod nginx
Attempts:
2 left
💡 Hint
Check the order and syntax of flags for port and environment variables.