Working with Docker in CentOS 7/RHEL 7

Working with Docker in CentOS 7/RHEL 7

You have installed Docker and run the image and create the docker container in last two post. Now, in this post “Working with Docker in CentOS 7/RHEL 7”, we are going to learn some basic docker commands so let’s working with Docker in CentOS 7/RHEL 7.

How to install Docker on CentOS 7.x

How to manage Docker containers on CentOS/RHEL 7.x

How to Start/Stop/Attach Container

To stop container use following command.

You can stop to any containers with following commands.

~]$ docker stop CONTAINER_ID
Working with Docker in CentOS 7/RHEL 7

To start container use following command.

~]$ docker start CONTAINER_ID
Working with Docker in CentOS 7/RHEL 7

To attach to currently running container use following command.

~]$ docker attach ffaaaf27f068
Working with Docker in CentOS 7/RHEL 7

How to list running Docker containers :

~]$ docker container ls
OR
~]$ docker ps 
Working with Docker in CentOS 7/RHEL 7

How to run a command in a running container

Run cat /etc/hostname command for docker container will show you output of /etc/hostname file

~]$ docker exec ffaaaf27f068 cat /etc/hostname

Run df -hT command for docker container will show you the file system information on running container

~]$ docker exec ffaaaf27f068 df -hT
Working with Docker in CentOS 7/RHEL 7

The top command shows running process and their details.

~]$ docker top ffaaaf27f068

The stats command does live stream of resource usage statistics, the output of this command will look like a normal top command.

~]$ docker stats ffaaaf27f068

The cp command will help you to copy files/folders from containers to a host system; the following command will copy “to be copied” to /root of a host machine.

~]$ docker cp ffaaaf27f068:/root/ghansham.txt /home/ghansham/

The rename command allows you to change the name of the container, following command rename the adoring_mahavira to ghansham-centos

~]$ docker rename adoring_mahavira ghansham-centos

To run the docker inspect to get the container IP address

~]$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
<container ID OR Name>

OR

docker inspect <container ID OR Name> | grep "IPAddress" 

OR

Docker Document Reference : Docker Docs


Hopefully “Working with Docker in CentOS 7/RHEL 7 ”, this will helps your understanding. More post related to Docker

Tagged , , , , , . Bookmark the permalink.