liveBook · Manning

Detached mode

As explained in Learn Docker in a Month of Lunches, Second Edition

Detached mode runs a container in the background without attaching the user's terminal to it.

Detached mode starts a container in the background and returns control of the terminal instead of attaching the session to the container. section 2.4 section 19.1

Use detached mode when a container should keep running as a service:

  • Add --detach, or -d, to run a container in the background. section 2.4
  • Add --publish when the background container must receive traffic through a host port. section 2.4
  • Check that the container is running with docker container ls. section 2.4
  • Read output with docker logs, including after stopping the container. section 19.1

Run a web container in detached mode

Run docker container run --detach --publish 8088:80 diamol/ch02-hello-diamol-web:2e. Docker returns a container ID, keeps the web server running, and maps host port 8088 to container port 80. Verify it with docker container ls and look for an Up status. section 2.4

docker container run --detach --publish 8088:80 `
 diamol/ch02-hello-diamol-web:2e

Shows the complete detached-mode command with port publishing. section 2.4

# run a detached container:
docker run -d --name timecheck diamol/ch19-timecheck:2e
# check the most recent log entry:
docker logs --tail 1 timecheck
# stop the container and check the logs again:
docker stop timecheck
docker logs --tail 1 timecheck
# check where Docker stores the container log file:
docker container inspect --format='{{.LogPath}}' timecheck

Shows detached execution followed by log inspection, stopping, and log-path inspection. section 19.1

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Defines background execution, terminal detachment, port publishing, and log retrieval without detailing Docker daemon internals.
Examples
Uses a background web server mapped from port 8088 to 80 and a time-checking container inspected through its logs.
What it assumes
Assumes basic Docker command usage while introducing foreground and detached container behavior through runnable commands.
What you can do after
Operate/configure Docker containers in the background, publish ports, verify status, and retrieve logs.
How it connects
Connects Docker containers with port publishing, container logs, stdout, stderr, and container lifecycle.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.