5. Docker Exec

  • Execute

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

5.2. What application is running inside the container?


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

5.4. Kill container

  • Terminate container instantly

$ docker kill CONTAINER_NAME_OR_ID

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

5.6. Inspect

$ docker inspect alpine

5.7. Update

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

$ docker update --restart=no alpine