In Jack Wallen’s Methods to Make Tech Work tutorial, he exhibits how utilizing the Docker exec command supplies you with extra flexibility.
Do you know you may difficulty instructions inside a working Docker container? It’s a really helpful option to do issues like replace software program, restart providers and far more. Even higher, Docker makes this beautiful simple, because of the exec command.
There are two methods you should use exec. The primary is to achieve entry to a working container’s shell, the place you may then run any command as should you’re on the Linux terminal. To do that, you may first find the working container’s ID, which may be achieved with the command
docker ps
With that ID in hand, you may 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.
As soon as on the bash immediate, you may difficulty the instructions you require, reminiscent of
apt-get replace && apt-get improve
When you’re achieved, you may exit the container with this command
exit
However what if you wish to skip step one and execute the identical instructions from outdoors the container? That is additionally potential utilizing the exec command.
Let’s say you wish 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 outdoors the container.
Get pleasure from this new flexibility that comes with the Docker exec command.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the most recent tech recommendation for enterprise execs from Jack Wallen.
