Skip to content

Docker commands

Daisho Komiyama edited this page Jan 3, 2023 · 4 revisions

Run a container

This will download the official Ubuntu container from Docker Hub and grab the version marked with the bionic tag.

docker run -it --name my-stuff --rm --privileged ubuntu:bionic

--name = gives the container a name (in this example: docker-host) so that you can recognize your container easily on docker ps

--rm = removes if there's a running process with the same name, then runs a new one

-it = makes the shell interactive (so we can use it like a normal terminal.)

Print the list of running containers

docker ps

Print all containers (including stopped containers)

docker ps -a

Get into a running container

This will let you run arbitrary commands inside an existing container.

docker exec -it <mycontainer> bash

-i = interactive mode (such as when starting a bash shell)

-t = pseudo-terminal (i.e., pseudo-tty)

Attach (you) to a running process

docker attach <container_name>

Stop a running container

docker kill <container_name>

Remove a container

docker container rm <container_id>

Remove all stopped container

docker container prune

Remove unused data

docker system prune

Remove a docker image

docker rmi <image_id>

or

docker image rm <image_id>

Print image history

docker history <image_id>
Clone this wiki locally