Basic Docker commands for CentOS / RHEL

Simple Docker guide to get you started with basics on CentOS. 

We already got through installation here – https://www.informaticar.net/install-docker-on-centos-rhel-8/. Now, lets get through few commands which will make Docker more clear to us.

If you followed my Docker install tutorial, you also added your user in Docker group, and after you log out/in you will be able to execute Docker commands without sudo. If you haven’t done that step, you will need sudo before every Docker command.

After the installation, we can verify Docker installation by issuing following command

sudo docker container run hello-world

If you need help and description of commands in Docker, execute

docker --help

Install Docker images

Docker image includes application, dependencies, libraries… In short, everything that one application needs to function. Docker got so popular because developers could assure that every time they deploy app it is the same environment. There are no variables that are changing (different hardware, software versions…) that would break the app.

Docker Hub is among other things a repo for public or private images. We will now learn how to search it, and “pull” software from it.

We will install another instance of Centos. We will first search for Centos image.

docker search centos

Ok, so the search found official centos image in Docker Hub.

We will install it by issuing following command

docker image pull centos

Lets now see, what Docker images our system is running.

docker image ls

If you wish to remove Docker image, you will run

docker image rm centos

Docker Containers

Image instance we installed is called container. We can manage container by running docker container subcommand.

To start Docker container you will run:

docker container run centos

Command started and then stopped centos container, because it is empty, there is no app or process to run on it.

To list running container you can run following

docker container ls

To see both running and stopped containers execute

docker container ls -a

At last, we will login into centos container we downloaded

To login to your container, run following

docker container run -it centos /bin/bash

We are now logged into our centos container.

To log out, type

exit

To remove container you will run

docker container rm CONTAINERID

Ok, these are in short basic commands to get you started. There is of course a lot more, but on other topics, some other time.

Disclaimer