Run a Docker Command Inside a Running Container Without Login

There are times when we only need to run a command inside a Docker container without actually accessing the container, and this post will show you how to do it.

This post will show how to run a command inside a Docker container directly from a Docker host or client.

Execute

To run commands, we use the docker exec command with the container name and the command we need to run. In the following example, I have a Docker container called deploy01 that I will run the df -h command against.

docker exec deploy01 df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay         251G  4.7G  234G   2% /
tmpfs            64M     0   64M   0% /dev
tmpfs           6.1G     0  6.1G   0% /sys/fs/cgroup
shm              64M     0   64M   0% /dev/shm
/dev/sdc        251G  4.7G  234G   2% /etc/hosts
tmpfs           6.1G     0  6.1G   0% /proc/acpi
tmpfs           6.1G     0  6.1G   0% /sys/firmware
Published
Categorized as Docker

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.