6. Exec

6.1. Attach to running containers

  • Attach to running container and execute another process of bash

$ docker exec -it CONTAINER_NAME_OR_ID sh
$ docker exec -u 0 -it CONTAINER_NAME_OR_ID sh      # as root

6.2. What application is running inside the container?

$ docker top CONTAINER_NAME_OR_ID

6.3. Stop containers

  • Filesystem inside container is ephemeral (it will be deleted after stop)

  • Allow container to close gracefully

$ docker stop CONTAINER_NAME_OR_ID

6.4. Kill container

  • Terminate container instantly

$ docker kill CONTAINER_NAME_OR_ID

6.5. Remove container

  • Remove container

    $ docker rm CONTAINER_NAME_OR_ID
    
  • Remove all stopped containers

    $ docker rm $(docker ps -a -q)
    
  • --rm - Automatically remove the container when it exits

    $ docker run --rm -it alpine sh
    

6.6. Inspect

$ docker inspect alpine

6.7. Update

  • Do not autostart alpine container after Docker engine restart (host reboot)

$ docker update --restart=no alpine