0
0
Dockerdevops~5 mins

Executing commands with docker exec - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the docker exec command do?
It runs a new command inside a running Docker container without starting a new container.
Click to reveal answer
beginner
How do you run an interactive shell inside a running container named webapp?
Use docker exec -it webapp /bin/bash to open an interactive bash shell inside the container.
Click to reveal answer
intermediate
What does the -it option mean in docker exec?
-i keeps STDIN open, and -t allocates a pseudo-TTY, allowing interactive commands.
Click to reveal answer
beginner
Can you use docker exec to run commands in a stopped container?
No, the container must be running to use docker exec.
Click to reveal answer
beginner
How do you run a one-time command like ls /app inside a container named backend?
Run docker exec backend ls /app to list the contents of the /app directory inside the container.
Click to reveal answer
What is required before you can use docker exec to run a command inside a container?
AThe container must be running
BThe container must be stopped
CDocker daemon must be stopped
DThe container must be paused
Which option allows you to run an interactive shell inside a container?
A-it
B-d
C-rm
D-p
What happens if you run docker exec without specifying a command?
AIt starts a new container
BIt lists running containers
CIt stops the container
DIt returns an error
How do you run a command inside a container named db to check the current directory?
Adocker start db pwd
Bdocker run db pwd
Cdocker exec db pwd
Ddocker stop db pwd
Which of these commands opens an interactive shell inside a container named app?
Adocker run -it app /bin/sh
Bdocker exec -it app /bin/sh
Cdocker exec app ls
Ddocker start -it app
Explain how to use docker exec to run an interactive shell inside a running container.
Think about how to keep input open and allocate a terminal.
You got /4 concepts.
    Describe the limitations of docker exec regarding container state and command execution.
    Consider when and how <code>docker exec</code> works.
    You got /4 concepts.