docker basic commands

Views:
 
Category: Education
     
 

Presentation Description

Docker container command is must for every docker admin. Because these basic docker containers commands used on daily basis in our infra. https://linuxdady.com/docker-container-command-for-beginners/

Comments

Presentation Transcript

slide 1:

LinuxDady.Com Docker container commands for Beginners For more information visit https://linuxdady.com

slide 2:

Docker container command Docker container command for beginner think you are well known about basic terminology of docker. Now in this tutorial we are going to learn docker container commands that will be very helpful when we will work on docker. Without knowledge of these docker command nobody can work properly on docker. So you should aware about these basic commands of docker container. Docker container command let’s suppose we have installed docker properly on our machine already. Now our first command become how to start and enable docker service. 1 2 3 4 5 systemctl start docker systemctl enable docker systemctl stop docker systemctl restart docker systemctl status docker Click Read: – How to install docker in Linux flavor Click Read: – What is docker container terminology docker images This command will help to show list of images on you docker host. Still we don’t have pull any image so it’s showing empty 1 docker images docker search By docker search command we can search our desired image on docker hub portal means let’s suppose I need MySQL docker image then run below command . It will show all trusted and open source images list that is available on docker hub. 1 docker search mysql

slide 3:

docker pull docker pull command is used to pull your desired image from docker hub or any third-party repository means by this command you can bring you images from any repository to you docker host. In my case I want to pull mysql image from docker hub to my docker host. 1 docker pull mysql How to launch container from your desired images

slide 4:

In above command we have pulled our desired mysql image. Now we want to launch container from that image. There are two mode in which we can launch container ▪ Demon mode -d ▪ Interactive mode 9 -it Demon mode – when your process is running in the background that is called demon mode. When we run the container in demon mode the we will use -d option to run in demon mode. docker run -d image name 1 docker run -d mysql:latest If any variable set for mysql password then you can run by below commands. 1 docker run --name con1 -e MYSQL_ROOT_PASSWORDredhat -d mysql:latest Container Name – con1 MySQL Password – redhat e – use to pass variable value docker logs If you are facing any issue by docker logs command you can check logs file. Let’s suppose you want to check logs of mysqld service then run below command. Con1 is container name where our mysql service is running 1 docker logs con1

slide 5:

If we want to start and stop our running containers then below command will be helpful. Con1 is our container name. 1 2 docker start con1 docker stop con1 docker rm From docker container command list docker rm command is used to remove existing container from your docker host. 1 docker rm con1 docker rmi docker rmi command is used to remove existing docker image from docker host. We can also use -f option to remove images force fully. 1 docker rmi -f mysql

slide 6:

docker ps docker ps command is user to check currently how many containers are running on your docker host. 1 docker ps docker ps -a This command will give complete detail of running containers means at which time your container is started or stopped etc. 1 docker ps -a How to monitor container docker top docker top command is used to monitory our running container on docker host. Here con4 con6 apache is my container name. let’s monitor these containers. 1 docker top con1

slide 7:

docker ps -aqf “namecontainername” By this command we can track out container id. Like con4 and apache is my container and I want to know my container id the follow us. 1 2 docker ps -aqf "nameapache" docker ps -aqf "namecon4" docker inspect If you want to know your running container IP address then use docker inspect command. 1 docker inspect con4 How to login into interactive mode in container. con10 is container name. But before moving to next we should know about demon mode and interactive mode.

slide 8:

Demon mode – When you launch a container from packed image means that image have already service like apache Mysql etc. So when we will launch container from this image then that service will start automatically in the background that is called demon mod. Interactive mode – When we launch a container from base layer image like centos Redhat etc. Then we have to configure all service manually. So we have to take it terminal access that is called interactive mode. 1 docker exec -it con10 /bin/bash exec – execute it – interactive mode 1 docker run span style"color: 000080"-it/span --name con11 centos:latest Difference between exec and run command exec – exec option stand for execute means when we have launched container already and we want to go inside container then this option used. run – When we want to launch new container and after launching that container we want to go inside that container then run option used. docker attach docker attach command is use to enter into your container means directly you can enter into you container without exec and run command. But remember one thinks this command will work only when container must have /bin/bash shell. 1 docker attach testing

slide 9:

How to do port forward for container Port forward is mandatory when you are running more than one service like let’s suppose we want to run more than one webserver in our container. Then we have to forward port from our docker host to our desire container. Here 8001 is my docker host port and 8080 is my service port that is running into the container. 1 docker run -d -p 8001:8080 centos/httpd-24-centos7:latest docker stats docker stats command is used to check running container how much RAM is utilizing from your total memory of docker host. Con1 is my container name let’s check RAM utilization. 1 docker stats con1 Conclusion Docker container command is must for every docker admin. Because these basic docker containers commands used on daily basis in our infra. So with the help of these basic command we can work smoothly in our production environment. If still you have any query on docker container command then you can write me in comment box. I will try my best to resolve them. Interview question on docker container commands

slide 10:

1 What is difference between run and exec command 2 What is difference between exec and attach command 3 What is difference between demon mode and interactive mode 4 When I launched a new container then immediately container exited means become stopped. What will be best approach to troubleshoot that 5 How to wide list port in docker

authorStream Live Help