Agentic AI with Java: Live Cohort
DockerContainers & Images

Essential Docker Commands

The everyday Docker commands for running, listing, stopping, removing, and inspecting containers and images.

Docker has many commands, but beginners should first become comfortable with the commands used every day.

These commands help you run containers, check what is running, view images, inspect logs, stop containers, and clean up after practice.

Check Docker installation

Start with:

docker version
docker info

docker version shows the client and server versions. docker info shows details about the Docker Engine, storage driver, running containers, images, and system configuration.

If these commands work, your terminal can talk to Docker.

Run a container

Use docker run to create and start a container from an image.

docker run hello-world

If the image is not available locally, Docker downloads it first.

To run an Nginx web server:

docker run nginx

This starts the container in the foreground, so logs appear directly in the terminal.

List running containers

To see running containers:

docker ps

To see all containers, including stopped ones:

docker ps -a

This is one of the most useful Docker commands. Use it often.

List images

To see images available on your machine:

docker images

Images stay on your system until you remove them. Running a container does not automatically delete the image.

Stop and remove containers

Stop a running container:

docker stop container-id

Remove a stopped container:

docker rm container-id

You can use either the container ID or container name.

Remove images

To remove an image:

docker rmi image-name

If a container is still using that image, Docker will not remove it. Remove the container first.

View container logs

To see logs from a container:

docker logs container-id

This is useful when an application starts but does not behave as expected.

Command summary

CommandPurpose
docker versionCheck Docker client and server version
docker run imageCreate and start a container
docker psShow running containers
docker ps -aShow all containers
docker imagesShow local images
docker stop idStop a running container
docker rm idRemove a stopped container
docker rmi imageRemove an image
docker logs idShow container logs

Do not try to memorise every Docker command at once. Start with run, ps, images, stop, rm, and logs. These cover most beginner practice.

Written By: Shiva Srivastava

How is this guide?

Last updated on