Engineering scalable systems, cloud-native applications, and AI-powered solutions.

How to execute shell command on running docker container?

Use the below syntax:

Ankush Jain

Ankush Jain

Lead Software Engineer (VP) | Software Architect

Published May 3, 2020Updated Nov 24, 2026

Use the below syntax:

bash
docker exec -ti <container_id> <command>

To check the container id, run docker container ls command in the console.

Examples:

  • To print date in the console - docker exec -ti date
  • To echo Hello World in console - docker exec -ti 011f0b0f68ce echo "hello world"
  • To create a directory inside container - docker exec -ti 011f0b0f68ce mkdir -p "/home/databox"

Reference - https://docs.docker.com/engine/reference/commandline/exec/

Have feedback or thoughts?

Discuss this article or share it on Twitter / GitHub.