Docker A to Z
Published: 2023-10-16 03:15:11



> **_docker ( double tab )_**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uuvdzdu0msh2d77zkbo9.png)

> **_Help command_**

```
docker volume help
docker image help
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avpy8jozonhdqnopia5b.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h49qu5i173dpntm3kykk.png)

> **_docker info_**

- docker system information will be displayed.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d7kli73dy9tsqrze4l6y.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3sfejlhyhsp9wmaz4ag.png)

- Above highlighted option will be ENABLED when we use CLUSTER in docker.

> **_docker system df_**

- All images & containers will be displayed.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8162iqbs0z1vb14ip0hu.png)

> **_Docker real-time Events or logs_**

```
docker system events
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/32v8oklzeid56gz6b1gx.png)

> **_docker system prune_**

- It deletes all image and container.
- Its a risky command as it removes unused data & free size.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jk1nnh51ficye4wgdby.png)

> **_help or man_**

```
man docker system
or
docker system help

```
> **_docker stats_**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ygiqztg0yxozoyqw3ams.png)

- Usage details are shown here.

> **_docker search busapp_**

- this search command , will get all the application i.e busapp installed in public repository of docker.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6y3c4z4gm7j0edu7odwt.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n4itx7u4ubppxp1vc43v.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8yob6mv0r25m5va7h5ka.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yrz7as6760jrtzipm2p1.png)

> **_docker images_**

- List the images which are present in the system.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8m6ujqvi6hi9z5mg2blf.png)

> **_Pulling the image from HUB_**

- why am I pulling the image ? To launch a container I need an image.
```
docker pull httpd
docker images
docker pull alpine
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d59bckse1bxkekeqt6t8.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ns7oz10mas1nj60l2bbz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wl04nua8zzf0l93d1dbv.png)

> **_Where these images stored ?_**

- It will be occupying your disc.
- Check it with df command.

```
docker system df
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hg43itah1pnl4xpsfz2.png)

> **_How to run a IMAGE ?_**

- There are two things , one is create & run
- CREATE --> Create the container but not in running state.
- RUN --> Create the container & run the container too.

```
docker run --name testing_web httpd
docker ps

--name --> Name for the container 
httpd --> name of the image

```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0jm35sxs4vp6b0myk8u4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d2rv0l1n6ohsrb2ut0aq.png)

- But the above one is running in foreground , so you can't perform anything in that window . But the container will come up. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnpbhe7xtzwp6uz0fx6w.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mg51xvrelv4ttbqysbjb.png)

- CONTROL + C ( now the container will not be available )

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lkpw7vdm488uvcv2iztu.png)

> **_RUN the container in back-ground_**

```
docker run -d --name testing_web httpd
docker ps -a ( shows all the container running & stopped )
d --> for demonize which runs in back-ground 

```

- Running the same command will end up in error because as we are using the same container name . Even though we stopped but the container is still there. IN other words " Its stopped but still the container is available in that name.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r127pubstemgm6yiwucs.png)

- Provide a NEW NAME to the container.

```
docker run -d --name testing_web_new httpd
docker ps
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tk2bnow3l371sl9dvoih.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4jv2bnyamqh1bn7u4aa6.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/teh58bhn7dq42lg85rs8.png)

> **_Lets login to the CONTAINER_**

```
docker exec -it testing_web /bin/sh
docker exec -it testing_web /bin/bash

testing_web  --> container name
/bin/sh --> shell type , we ca use bash also.
it --> Interactive terminal 

```
Here the trick is that , NOT all commands we can run inside this container . Check it. Also we are not aware what OS they used to build the image.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u87tc9uxnigns6056eue.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ma8dkzdnhx4iv3juqtjk.png)

- It will only files which are related to httpd only.
- only these commands can be used inside the container.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n2crs3mlohxiqngve03l.png)

> **_Without logging in Can we execute COMMANDS ?_**

- YES
- Remove the 'it' from the command.

```
docker exec testing_web_new uname -a
docker exec testing_web_new hostname
docker exec testing_web_new mkdir /tmp/testing_dir
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hh8vy4qpuj89mmffffn.png)

> **_Copy FILES from local to CONTAINER_**

```

docker cp <file_name_local> <container_id/conatiner_name>:<destination>
docker ps
docker cp local_file 6438c81d6841:/tmp
docker exec testing_web_new ls /tmp
docker cp local_file testing_web_new:/tmp
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uz7p1f2s2c7l7zwli8uw.png)

> **_Copy FILES from CONTAINER to Local_**

```
docker cp <file_name_local> <container_id/conatiner_name>:<destination>
touch local_to_container
docker ps
docker cp local_to_container 4b:/tmp
docker exec os_service_3 ls /tmp
rm local_to_container
docker cp 4b:/tmp/local_to_container .

Note : 4b --> Nothing but start of the container. You can give in this WAY.
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lq23glkkyoi5221pq9e5.png)



> **_How to START & STOP the CONTAINER?_**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2y7g9gf6ashmywuiv60.png)

```
docker ps -a
docker stop testing_web_new
docker ps -a
docker start testing_web_new
docker start testing_web
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3w40yay0sa0m1542z5s.png)

> **_System related check for these containers_**

```
docker system df
docker stats
docker stats <container_name>
docker top <container_name>
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vwl5qbw7wcnq224wxxox.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ky5n46lwacge07mkos48.png)

> **_How to remove the CONTAINER ?_**

- Keep in Mind " You cant remove a RUNNING Container ". But we can with FORCE option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tq0apz0c4za2pgb4ru3z.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ituvrm5aoumcwajj3b2y.png)

- Before remove , STOP the container. ( safest way )

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vyzscwhrtl88k9tv3tm0.png)

```
docker ps
docker rm testing_web_new
docker rm -f testing_web_new
docker ps
docker stop testing_web
docker rm testing_web
docker ps
```

> **_docker logs_**

- By giving the container Name , we can check the logs.
- Start logs only visible.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x3jxsgqoa7x23cra2lnq.png)

- LETS start the alpine and check the logs.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3qax4nmwfohrsd882ss.png)

- Above screen shows Alpine is started but its not running.
- Alpine is just a OS , so we need to provide what type of bash is required.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jrmhnfggiqwupsabb1f.png)

```
docker run -d --name os_service_2 alpine /bin/sh --> NOT WORKING / ERROR
docker run -d --name os_service_1 alpine /bin/sh --> NOT WORKING / ERROR
docker run -d -it --name os_service_3 alpine /bin/sh
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0jmir94q34vhlxrjswa.png)

> **_System Prune_**

- Clear the container.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/co9rtclpxxno8nj8473c.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hogeogg4evtcz97nxe9k.png)

```
docker system prune
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jc82zwk40k87xz0cyky9.png)

- EXITED all got deleted.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gttpzvqi8ytng2bgfe1w.png)

Reference :



[ **TO BE CONTINUED** ]