Docker Installation and basics  Commands of Docker.
Published: 2020-08-27 08:27:19

_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  
 
https://dev.to/yashwantap/series-of-docker-3a5e