How do i attach to a docker container?



  • Man page for docker attach.

    Note: Control-C after attach stops the container, there is an escape sequence if running a tty.

    You can attach to a container to see output for instance. Here we loop the date command to demo the docker attach command.

    Create a container to loop the date command.

    $ docker run -d alpine /bin/sh -c 'while x=0; do echo $(date);sleep 10;done'
    fe8970c83f43b0d2d765d600239f57557edf007fe5c4501ac7cf99fe5e910e87
    

    Attach to the container and see date changing every ten-seconds.

    $ docker attach fe8970c83f43                                                
    Wed Jan 9 14:04:12 UTC 2019
    Wed Jan 9 14:04:22 UTC 2019
    ^C
    

Log in to reply
 

© Lightnetics 2024