Docker - Common Commands

by

This tutorial will introduce you to the very basic Docker / Podman commands. You should memorize these, as you'll use them often.

Pulling an image

To download an image to your computer, use the following command as an example for how to pull an nginx image:

docker pull nginx

Listing docker images

To list all locally available images use the following command:

docker image list

If you followed my previous tutorial you should already have an hello-world image available. If not, please pull it.

Note the Image ID.

Removing an image

To remove a local image use this line:

docker image rm 

Running a container

To execute the hello-world image you downloaded earlier, execute this line:

docker run hello-world

For the next example, please run a container that will not finish immediately, such as an apache server. Simply replace "hello-world" with "httpd".

List running containers

To show all running containers:

docker container ls

Note the container ID.

Remove container

You can also remove a container this way:

docker container rm 

Getting a bash shell to a running container

If you have a container running in the background, you can get a bash shell to it this way:

docker exec -it  bash

Getting logs from a container

You can inspect a container's stdout like so:

docker logs 

You should now know enough to start playing with containers on your own, have fun!