docker

What is the difference between "docker logs" and "docker attach"?


They both allow you to connect to the stdout/stderr of a running container. In particular docker logs --follow seems to work similarly to docker attach.

Is one command an obsolete version of the other, or are there significant differences?


Solution

  • docker logs just pipes you stderr/stdout, while docker attach attaches stdin/out/err and proxies signals.

    For example, the docs for docker container attach states

    You can detach from the container again (and leave it running) with CTRL-p CTRL-q (for a quiet exit), or CTRL-c which will send a SIGKILL to the container, or CTRL-\ to get a stacktrace of the Docker client when it quits. When you detach from the container's process the exit code will be returned to the client.

    If the container has a pty I would assume you get attached to the pty and have full pty features (haven't tested that).

    Hope this helps a bit!