How to Easily Run Commands Inside a Running Docker Container

0
1059
How to Easily Run Commands Inside a Running Docker Container


In Jack Wallen’s How to Make Tech Work tutorial, he exhibits how utilizing the Docker exec command gives you with extra flexibility.

Did you understand you possibly can subject instructions inside a operating Docker container? It’s a really helpful option to do issues like replace software program, restart providers and way more. Even higher, Docker makes this gorgeous simple, due to the exec command.

There are two methods you should use exec. The first is to achieve entry to a operating container’s shell, the place you possibly can then run any command as if you happen to’re on the Linux terminal. To do that, you may first find the operating container’s ID, which may be achieved with the command

docker ps

With that ID in hand, you possibly can entry the container with a command like

docker exec -it ID /bin/bash

the place ID is the primary 4 characters of the container ID in query.

Once on the bash immediate, you possibly can subject the instructions you require, equivalent to

apt-get replace && apt-get improve

Once you’re achieved, you possibly can exit the container with this command

exit

But what if you wish to skip step one and execute the identical instructions from exterior the container? This can be potential utilizing the exec command.

Let’s say you need to run the identical instructions for updating and upgrading the software program in your container. You’ll nonetheless want the container ID and may run a command like

docker exec ID apt-get replace && sudo apt-get improve -y

the place ID is the primary 4 characters of the container ID in query.

You’re not restricted to only updating and upgrading your containers; any command that may be run from the bash immediate may be run from exterior the container.

Enjoy this new flexibility that comes with the Docker exec command.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the newest tech recommendation for enterprise professionals from Jack Wallen.

LEAVE A REPLY

Please enter your comment!
Please enter your name here