Summary - docker run
- Docker & Kubernetes course
- Beginner
- Lesson 36/82
- 5 min
Combine various run flags to run an interactive container.
Summary: docker run
In this group:
-itopens an interactive terminal; Ctrl+P, Ctrl+Q detaches without stopping.--namegives a unique name;docker renamechanges it.--restart(no,on-failure,always,unless-stopped) provides resilience.-w,--entrypoint,-uoverride image settings.- Containers should run as an unprivileged user with
USERinstead of root.
docker run -d --name api --restart unless-stopped -u 1000:1000 -w /app api:1.0Practice A production-like run
Start a container from the api:1.0 image with a single command: in the background, named api, restarting unless stopped by hand, with the user 1000:1000 and the working directory /app.
Starter code
# buraya yazExpected output
6e7f8a9b0c1d
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command is best for inspecting the inside of an image?
- docker run --rm -it --entrypoint sh image Correct answer
- docker logs image
- docker build image
- docker stop image
Explanation: Replacing the entrypoint with a shell starts a shell instead of the application.
2 Run the container as UID 1000.
docker run --rm ____ 1000:1000 alpine id
docker run --rm -u 1000:1000 alpine id
Explanation: -u takes a user or UID:GID.
3 Match.
| Term | Meaning |
|---|---|
-it |
Interactive |
--restart |
Restarting |
-w |
Directory |
-u |
User |