0
0
Dockerdevops~20 mins

Attaching to running containers in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Attach Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of attaching to a running container
You have a running Docker container named webapp that outputs logs continuously. What will be the output of the command docker attach webapp?
Docker
docker attach webapp
AYou will get an error saying the container <code>webapp</code> does not exist.
BYou will see the live output stream (logs and console) of the <code>webapp</code> container.
CThe command will detach immediately without showing any output.
DThe command will start a new container named <code>webapp</code> and show its logs.
Attempts:
2 left
💡 Hint
Think about what docker attach does to a running container.
💻 Command Output
intermediate
2:00remaining
Effect of detaching from a container
You attached to a running container using docker attach mycontainer. Which key sequence will safely detach your terminal without stopping the container?
APress <code>Ctrl+P</code> then <code>Ctrl+Q</code>
BPress <code>Ctrl+Z</code>
CPress <code>Ctrl+C</code>
DPress <code>Ctrl+D</code>
Attempts:
2 left
💡 Hint
Detaching requires a special key sequence to avoid stopping the container.
Troubleshoot
advanced
2:00remaining
Troubleshooting attach failure
You run docker attach myapp but get the error: you cannot attach to a stopped container. What is the most likely cause?
AYou do not have permission to attach to the container.
BThe container <code>myapp</code> is running but has no output streams.
CThe Docker daemon is not running on your machine.
DThe container <code>myapp</code> is not running; it is stopped.
Attempts:
2 left
💡 Hint
Check the container status before attaching.
Best Practice
advanced
2:00remaining
Best practice for interactive container sessions
Which command is best to start a new container and attach to it interactively with a terminal session?
Adocker run -it myimage
Bdocker run -d myimage
Cdocker attach myimage
Ddocker exec myimage
Attempts:
2 left
💡 Hint
Think about starting and attaching in one step with a terminal.
🔀 Workflow
expert
3:00remaining
Correct workflow to attach and detach safely
Arrange the steps in the correct order to attach to a running container named db, interact with it, and then detach safely without stopping it.
A2,1,3,4
B1,3,2,4
C1,2,3,4
D1,2,4,3
Attempts:
2 left
💡 Hint
Think about the natural order of attaching, using, detaching, and returning.