In Jack Wallen’s How to Make Tech Work tutorial, he shows how using the Docker exec command gives you more flexibility.
Did you know that you can issue commands into a running Docker container? It’s a very convenient way to do things like update software, restart services and much more. Best of all, Docker makes this quite simple, thanks to the executive order.
You can use two ways executive. The first is to access the shell of a running container, where you can then run any command as if you were on the Linux terminal. To do this, you can first locate the ID of the running container, which can be done with the command
docker ps
With this ID in hand, you can access the container with a command like
docker exec -it ID /bin/bash
where ID is the first four characters of the container ID in question.
Once at the bash prompt, you can issue the commands you need, such as
apt-get update && apt-get upgrade
Once you’re done, you can exit the container with this command
exit
But what if you want to skip the first step and run the same commands from outside the container? This is also possible using the executive order.
Let’s say you want to run the same commands to update and upgrade the software in your container. You will still need the container ID and can run a command like
docker exec ID apt-get update && sudo apt-get upgrade -y
where ID is the first four characters of the container ID in question.
You’re not limited to just updating and upgrading your containers; any command that can be run from the bash prompt can be run from outside the container.
Take advantage of this new flexibility that comes with Docker executive order.
Subscribe to TechRepublic How to make technology work on YouTube for all the latest tech tips for professionals from Jack Wallen.