This tutorial explains essential Docker debugging commands: docker logs displays container output for troubleshooting issues, while docker exec -it provides an interactive terminal inside running containers to navigate the file system, check configurations, and execute commands. The video also covers container management commands including docker run (creates new containers from images), docker start (restarts stopped containers), and docker stop, along with container naming conventions for easier identification.
Debugging Docker Containers: Exec and Logs Commands Explained
Added:[Music] so so far we have seen a couple of basic docker commands we have seen dr. pool which pulls the image from the repository to local environment we also saw run which basically combines docker pool and docker start pulls the image if it's not locally available and then starts it right away then we saw dock a start and a stop which makes it possible to restart the container if you made some changes and you want to create a new version which makes possible to restart the container if you need to we also saw docker run with options the one option that we saw was D minus T which is detach so you can run the container djay detached mode so you can use terminal again - P allows you to bind port of your host to the container so very important to remember - P then comes the port of your host and then comes the port of your container whatever it might be we also saw dr. PS dr. PS - a which basically gives you all the containers no matter if they're running currently or not we also saw docker images which gives you all the images that you have locally so for example if after a couple of months you decide to clean clean up your space and get rid of some stale images you can actually check them check the list and then go through them and delete them you can do the same with stale docker containers that you don't use anymore or you don't need it anymore you can also get rid of them so the final part of the docker basic commands are commands for troubleshooting which are very very useful if something goes wrong in the container you want to see the locks of the container or you want to actually get inside of container get the terminal execute some comments on it so let's see dr. PS we have two containers running right now we don't have any output we don't see any logs here so let's say something happens your application cannot connect to Redis and you don't know what's happening so ideally you would want to see what logs Ready's container is producing right the way to do that is very easy you just say docker locks and you specify the container ID and you see the locks you can also do the lock logs if you don't want to remember the container ID or to dr. PS all the time you can remember the name of the container and you can get the logs using the name so a little side note here as we're talking about the names of the containers so here is you see when a container is created you just get some random name like this so you can name your containers as you want using another option of the docker run which might be pretty useful sometimes if you don't want to work with the container IDs and you just want to remember the names or if you just want to differentiate between the containers so for example let's create a new container from readies for the old image using a different name that we choose so I'm gonna stop this container and I'm going to create a new one from the same image so let's run it in the detached mode let's open the port 2000 1 2 6 3 7 9 and give the name to the container and let's go since it's the older version let's call it Redis older and we need to specify the image so remember this will create a new container since we're running the docker 1 command again so if we execute this and check we see the readies for the O image-based container is created which is fresh new you can see I created and the name is ready solder and we can do the same for the other container so that we kind of know which container is what so to stop this one and I will use the same command here this will be the latest and I will call this readies latest and since find another port so I'm gonna run it and let's see so here I have two containers running now I know Ready's older readies latest so for example if the older version has some problems I can just do logs readies older and I can get my locks so another very useful command in debugging is docker exec so what we can do with docker exec is we can actually get the terminal of a running container so let's check again we have two containers running and let's say there is some problem with the latest Redis latest container and I want to get a terminal of the container and - maybe navigate a directory inside check the lock file or maybe check the configuration file or print out the environmental variables whatever so in order to do that we use docker exit command with minus T which stands for interactive terminal then I specify the container ID and I say in flash so I get that - and here you see that the cursor changed so I'm inside of the container as a root user and here if I say LS okay the data is empty I can also print out in which directory I am can go to the home directory see what's there so I have my virtual file system inside of a container and here I can navigate the different directories and I can check stuff I can also print all the environmental variables to see that something is set correctly and do all kinds of stuff here and this could be really useful if you have a container with some complex configuration or if for example you are running your own application that you wrote in a container and you have some complex configuration there or some kind of setup and you want to validate that everything is correctly set in order to exit the terminal use the exit and you're out you can also do the same using the name again if you don't want to work with the IDs and you just want to remember the names of the container to make easier you can do it we the name is well same thing since most of the container images are based on some lightweight linux distributions you wouldn't have much of the linux commands or applications installed here for example you wouldn't have curl or some other stuff so you were a little bit more limited in that sense so you can execute a lot of stuff from the docker containers for most of the debugging work it should be actually enough so the final part to review the difference between lock run and docker start which might be confusing for some people let's revisit them so basically docker run is where you create a new container from an image so docker run will take an image with a specific version or just latest right as a option or as an attribute with docker start you not working with images but rather with Tanner's so for example as we saw the Quran has a lot of options you specify with minus D and minus P the port binding and then you have this name of the container and all this stuff so basically you tell docker at the beginning what kind of container with what attributes name and so on to create from a specific image but once the container is created and you can see that using a command for example here the last ones that we created and if you stop it and you want to restart it you just need to use the command docker start and specify the container ID and when you started the container will retain all the attributes that we defined when creating the container using docker run so dr. Ron is to create a new container toku start is to restart a stopped container thanks for watching the video I hope it was helpful and if he was don't forget to like it this is a video series so I will create a new one every week so if you want to be notified whenever a new video comes out then subscribe to my channel if you have any questions if something wasn't clear in the video please post them in the comment section below and I will try to answer them so thank you and see you in the next video
Up Next

FastAPI Tutorial: Build a REST API From Scratch in Python
@UnfoldDataScience
317.4K views•2023-01-03

IFS Therapy Demonstration: Complete Session with Unburdening
@IFSCA
95.9K views•2021-01-13

Prometheus Monitoring Architecture: A Technical Guide
@TechWorldwithNana
1.2M views•2020-04-24

Game of Thrones Opening Credits: A Cinematic Analysis
@gameofthrones
46.3M views•2011-04-18
Related Study Plans & Knowledge Roadmaps
Structured learning paths in General & Interdisciplinary Studies







































