In this documentation i'm taking you through the installation of docker as well as the basic commands of docker.
Prerequisite:
- You need a Linux based machine.
- Version 3.10 or higher of the Linux kernel.
- iptables version 1.4 or higher.
In this documentation i'm installing docker on CentOs machine.
If the machine already have the older version of docker then we have to remove that frist.
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
Now after cleaning the older package we can install new package of docker.
There are different ways to install the docker on your host machine:
- Most of users set up Docker’s repositories.
- Some of users download the RPM package and install it manually.
- In some of the scenario some users choose to use automated scripts to install Docker.
Let's try to install the docker with Configuring the Repository.
When you are installing the docker first time on your hosts machine, you need to configure the repository.
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
After configuring the repository of docker, use following command to install the it.
yum install docker -y
OR
yum install docker-ce docker-ce-cli containerd.io -y
After installing the docker successfully, you need to start of it's service.
systemctl start docker
After starting the service of docker we need to enable it. Because whenever you boots you system next time the docker service will start with system boot. you need not to start service manually.
systemctl enable docker
We can verify that the service is started or not.
systemctl status docker
Now everything is setup and we are good to go.
Basic Commands of the docker
1) To Check the version of docker , for that we use the command :
docker --version
2) To search any image, for that we use the command :
syntax: docker search image name
docker search ubuntu
3) To pull any image form docker repository , for that we use the command :
Syntax: docker pull image name
docker pull docker.io/ubuntu
4) To see the pulled images, for that we use the command :
docker images
5) To run the image which we pulled or which already present on local machine, for that we use the command :
Syntax: docker run -it -d image name
docker run -it -d --name demo docker.io/ubuntu
6) To check running containers, for that we use the command :
docker ps
7) To see all the running and exited containers, for that we use the command :
docker ps -a
8) To access the running container, for that we use the command :
Syntax: docker exec -it container id bash
docker exec -it d39a7dba62a0 bash
- exec: execute
- -it : Interactive
- bash: to get the bash shell
9) To creates a new image from an edited container
on your local system , for that we use the
command :
Syntax: docker commit conatainer id
docker commit d39a7dba62a0
10) To stop a running container, for that we use the command :
Syntax: docker stop container id
docker stop d39a7dba62a0
11) To kill the container we use command called
kill. It will kills the container by stopping
its execution immediately.
- The difference between ‘docker kill’ and ‘docker stop’ is that ‘docker stop’ gives the container time to shutdown gracefully.
docker kill d39a7dba62a0
12) To login to the docker hub repository we use:
docker login
After pressing enter it will prompt you for login and password of you docker hub repository.
13) To push an image to the docker hub repository we use:
Syntax: docker push username/image name
docker push usrname/ubuntu
14) To delete a stopped container , for that we use the command:
Syntax: docker rm container id
docker rm d39a7dba62a0
15) To delete an image from local storage, for that we use the command:
Syntax: docker rmi image-id
docker rmi 736a7gpb5ba1
16) The docker build command builds Docker images
from a Dockerfile. To build an image from a
docker file we use:
Syntax: docker build path to docker file
docker build . -t firstDcokerFile
- . (dot): it will point to current location.
- -t : Tag, You can give the name to docker file (Optional)
_ want to know what is docker and its architecture, see my first blog
Top comments (0)