CodeBlanks Logo Icon CodeBlanks

Summary - docker run

Combine various run flags to run an interactive container.

Summary: docker run

In this group:

  • -it opens an interactive terminal; Ctrl+P, Ctrl+Q detaches without stopping.
  • --name gives a unique name; docker rename changes it.
  • --restart (no, on-failure, always, unless-stopped) provides resilience.
  • -w, --entrypoint, -u override image settings.
  • Containers should run as an unprivileged user with USER instead of root.
docker run -d --name api --restart unless-stopped -u 1000:1000 -w /app api:1.0

Practice 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

terminal
# buraya yaz

Expected 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.

Question
docker run --rm ____ 1000:1000 alpine id
Answer
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

All lessons in Beginner