Skip to content

Docker: Logs & shells

5 Docker commands: Logs & shells. Click a command to see what each part does.

Index
5 items
Click a command to see what each part does.

Logs & shells5

  • docker logs -f --tail 200 -t <container>Follow the last 200 log lines with timestamps

    What each part does

    1. docker logs <container>the container's stdout/stderr
    2. -f--follow: keep streaming new lines
    3. --tail 200start from the last 200 lines (alias -n)
    4. -t--timestamps: prefix each line with its time
  • docker logs --since 15m <container> 2>&1 | grep -i errorLogs from the last 15 minutes, errors only

    What each part does

    1. --since 15monly lines from the last 15 minutes (also 1h30m or an RFC3339 time)
    2. 2>&1merge stderr into stdout, so grep also sees error output
    3. | grep -i errorkeep lines containing "error", any case
  • docker exec -it <container> shOpen a shell inside a running container

    What each part does

    1. docker exec <container>run a command in a running container
    2. -i--interactive: keep stdin open
    3. -t--tty: allocate a terminal
    4. shthe command to run (use bash if the image has it)
  • docker exec -e <KEY>=<value> -w <dir> <container> <cmd>Run a one-off command with env and workdir

    What each part does

    1. -e <KEY>=<value>set an environment variable for this command only
    2. -w <dir>working directory inside the container
    3. <cmd>command to run; wrap chains as sh -c "a && b"
  • docker cp <container>:<path> ./ ; docker cp ./<file> <container>:<path>Copy a file out of / into a container

    What each part does

    1. docker cp <container>:<path> ./container → current host directory
    2. ;then
    3. docker cp ./<file> <container>:<path>host → container

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…