3. Exec

3.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

3.2. What application is running inside the container?


3.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

3.4. Kill container

  • Terminate container instantly

$ docker kill CONTAINER_NAME_OR_ID

3.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

3.6. Inspect

$ docker inspect alpine

3.7. Update

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

$ docker update --restart=no alpine