Sometimes the best way to troubleshoot and understand how a Docker Container works, is by exploring the Container. While I believe there are couple of ways to explore, one of the ways I really found useful is docker exec. Basically docker exec let’s you run commands inside a Container, and for a Linux Container we can use docker exec to bash in and run shell commands.
But to bash in of course, you need to have the Container in running state. Here in this post, I have explained how you can setup your own Container, specifically a Linux Container with ASP.NET Core MVC Application running inside.
So let’s proceed.
Currently I have no Containers running.
docker ps -a |
And I have following set of Images.
docker images |
Here the dockerwebapp is the Image that I am planning of creating and running a Container from. I can run the Container by issuing docker run.
# Runs in the foreground # Even if pressed Ctrl+C, Container is still running PS C:\WINDOWS\system32> docker run dockerwebapp # Runs in the background/detached PS C:\WINDOWS\system32> docker run -d dockerwebapp # Runs in the foreground # If pressed Ctrl+C, Container will stop running # Container will be displayed in docker ps -a PS C:\WINDOWS\system32> docker run -it dockerwebapp # Runs in the foreground # If pressed Ctrl+C, Container will stop running and will get deleted PS C:\WINDOWS\system32> docker run -it –-rm dockerwebapp
In this case, I am going to run docker run –d dockerwebapp as I want the Container to be running in the background, so for next docker commands, I don’t want to open up another PowerShell window.
docker run -d dockerwebapp |
Now I can see that my container is running, it’s time to explore the image.
PS C:\WINDOWS\system32> docker exec -i -t blissful_roentgen /bin/bash # -i -t can be use together like follows PS C:\WINDOWS\system32> docker exec -it blissful_roentgen /bin/bash
docker exec |
You can see that I am now in a Linux shell and I can use shell commands to explore the image. For instance to see the file system.
Hope this helps.Happy Coding.
Regards,
Jaliya
No comments:
Post a Comment