LAB 7: Installing and Configuring Docker

LAB 7: Installing and Configuring Docker

1. Installing Docker

yum install docker -y

2. Docker basic commands

//To check the docker version
docker --version

//To check the status of the service
service docker status

//To start the docker service
service docker start

//To enable the service
chkconfig docker on

//To see images present in your local machine
docker images

//To search images from online docker registry
docker search centos
docker search jenkins

//Download image from online docker registry to your machine
docker pull centos
docker pull jenkins

//To see only running containers
docker ps

//To see all containers
docker ps -a

//To create a container
docker run -i -t ubuntu /bin/bash
docker run -i -t centos /bin/bash

//run commands inside the container
hostname
cat /etc/os-release

//to exit from container
exit

//To rename a container
docker rename <old_name>  <new_name>
docker ps -a

// Create container by giving container name
docker run --name Cnt-1 -it centos /bin/bash

//To start container
docker start Cnt-1
docker ps

//To go inside container
docker attach Cnt-1

//run commands inside the container
touch /tmp/myfile
exit

//To see the changes
docker diff Cnt-1

//To stop container
docker stop Cnt-1

//To create image from container
docker commit Cnt-1
docker images

//To give name to your image
docker tag <image-ID> Cnt-1-img
docker images

//To give name of image while creating it
docker commit Cnt-1 <image-name>

//Create container from our image
docker run --name Cnt-2 -it Cnt-1-img /bin/bash

//run the command inside container
ls /tmp

//To delete a container
docker rm Cnt-1

//To stop all containers
docker stop $(docker ps -a -q)

//To delete all stopped containers
docker rm $(docker ps -a -q)

//To delete all images
docker rmi -f $(docker images -q)