Docker for Beginner's
Tags: beginners, devops, tutorial, docker
Published: 2022-11-07 19:32:19

> Source from Zeal Vora,KPLABS Course(Premium Instructor at Udemy)
[Udemy](https://www.udemy.com/course/docker-certified-associate)

Zeal is one of my favorite author for docker. Please try to yourself 💖

**(Tip: HE is ready to give some discount for students 😜)**



-----------------Table of content-----------------
------------------------------------------------------------------

1. What is docker and why we need ?

2. Docker Installation and pre-requisite 

3. Image VS. Containers

4. Basic commands 

5. port binding

6. Attached and detached mode

7. Restart policy

8. Disk usage 

------------------------------------------------------------------
**1.Container and purpose** 

Docker is the set of alone process and container tool. Its easy to deploy the microservice with running application using the containers.

* Weightless 
* Movable
* Compact 

**2. Docker Installation and pre-requisite**

Docker available in variety of operating systems, this includes:

- Windows 
- Linux 
- MAC

The installation of Docker is pretty straight forward in each one of them.

[Docker installation](https://docs.docker.com/get-docker/)

**3. Image VS. Containers**

Microservice application (Recipe of microservice) procedural code is called image


![container](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xb16d3am31umt6cf4z0f.png)


Running docker image is called container.

![container](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/322834ed3somtw0uoha0.png)

**4. Basic commands**

`docker images` -  List the docker images

`docker pull image-name` i Pull the image from docker hub
`docker ps` - List the container
`docker stop container-ID` - Stop the container
`docker start container-ID` - Start the container
`docker rm -f image name` - Remove the docker image
`netstat -ntlp` - See the running port
`docker exec -it container-id /bin/bash` - Goto inside the container
`docker run -dt -p containerport:actualport --name=anyname conatainer id - Port mapping with container
`
`docker container stop $(docker container ls -aq)` - Stop the all container

`docker container rm $(docker container ls -aq)` - Remove the all container

**5. port binding**

Goto inside the container

`docker exec -it container-id /bin/bash` 

**Port mapping with container**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bce8lhb3cpglqnuljuml.png)
`docker run -dt -p 80:81 --name=anyname conatainer id` 

**6. Attached and detached mode**

`docker run -dt`

d - detached mode
t - terminal tty

When we start a docker container, we need to decide if we want to run in a default foreground mode or the detached mode.

You may want to use this if you want a container to run but do not want to view and follow all its output

**7. Restart policy**

 when docker daemon is stopped that time entire container goes 
 down. we avoid that situation so we using the restart policy

- no - Do not automatically restart the container
- on-failure - Restart the container if its exists due to an error
- unless-stopped - Restart the container unless it is explicitly stopped 
- always - Always restart the container if it stops


**8. Disk usage**

`docker system df`

![container](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xygzdozsukqzf0kuu3jr.png)