Docker

How to show the run command of a docker container

19 September 2026 · 9 min read

How to show the run command of a docker container

Understanding how Docker containers are created and configured is crucial for effective container management. One common task is figuring out the exact command used to run a container, especially when debugging or replicating environments. Learning how to show the run command of a Docker container allows you to understand the container’s configuration, including any specific parameters or environment variables. This knowledge is invaluable for troubleshooting, replicating environments, and ensuring consistency across your deployments. This guide will walk you through several methods to extract this information, providing you with the tools and techniques necessary to effectively manage your Docker containers and ensure they are running as intended.

Inspecting Docker Container Configuration with docker inspect

The docker inspect command is a powerful tool for retrieving detailed information about Docker objects, including containers, images, networks, and volumes. It returns a JSON document containing a wealth of data about the specified object. When applied to a container, docker inspect can reveal the command used to start the container, along with other essential configuration details. This method is particularly useful because it provides a comprehensive overview of the container’s settings, allowing you to understand exactly how it was configured at runtime. The command itself is straightforward to use, making it accessible even to those relatively new to Docker.

To use docker inspect to show the run command of a Docker container, you’ll need the container’s ID or name. You can obtain this using the docker ps command, which lists all running containers. Once you have the ID or name, you can execute the following command: docker inspect -f ‘{{.Config.Cmd}}’ <container_id_or_name>. This command uses the -f flag to specify a Go template that extracts the Cmd field from the container’s configuration. The Cmd field contains the command that was used to start the container. This approach is efficient and provides a clear, concise output of the run command.</container_id_or_name>

For example, if your container’s ID is a1b2c3d4e5f6, the command would be docker inspect -f ‘{{.Config.Cmd}}’ a1b2c3d4e5f6. The output will be a JSON array representing the command and its arguments. This method reveals the exact command executed within the container, helping you understand how it was launched. According to Docker’s documentation, using docker inspect is the most reliable way to retrieve detailed configuration information. [^1^][Docker Inspect Documentation]

Leveraging docker history for Image Command Retrieval

While docker inspect focuses on container-specific details, docker history allows you to examine the layers of an image and the commands used to create them. This is particularly useful for understanding the base image and any modifications made during the image-building process. By examining the image’s history, you can often infer the run command used within the container, especially if it was defined during the image creation process. This method is helpful when you don’t have direct access to the running container or when you want to understand the image’s origins.

To use docker history, you’ll need the image’s name or ID. You can obtain this using the docker images command. Once you have the image name or ID, execute the following command: docker history <image_name_or_id>. This command will display a list of layers, each representing a step in the image-building process. Look for layers that contain commands like CMD or ENTRYPOINT, as these often define the default command that will be executed when a container is created from the image. While not always a direct representation of the final run command (due to overrides at container creation), it provides valuable context.</image_name_or_id>

Keep in mind that the docker history command shows the commands used during image creation, not necessarily the exact command used when running a specific container. If the container’s run command was overridden using the docker run command, docker history will not reflect that override. However, it can still provide valuable insights into the image’s base configuration. This method is particularly useful when tracing the lineage of an image and understanding its intended purpose. For example, examining the history of a Node.js image might reveal the specific version of Node.js installed and the default command used to start the application. According to a study by Datadog, understanding the layers of your Docker images can significantly improve build times and resource utilization. [^2^][Datadog Docker Monitoring]

Using the docker ps Command with Formatting Options

The docker ps command, primarily used to list running containers, can also be customized to show the run command of a Docker container, albeit in a more limited fashion compared to docker inspect. By using formatting options, you can extract specific information about the container, including the command that was used to start it. This method is quick and convenient for a basic overview, but it may not provide as much detail as docker inspect.

To use docker ps to display the run command, you can use the -f flag along with a Go template. The following command will display the command for all running containers: docker ps -a –format “table {{.ID}}\t{{.Names}}\t{{.Command}}”. This command uses the –format option to specify a table with the container ID, name, and command. While this method doesn’t provide the full command with all arguments, it gives you a quick overview of the main command being executed. It’s a useful shortcut when you need a fast way to see what’s running in your containers.

It’s important to note that the output from docker ps might be truncated or simplified, especially for complex commands with many arguments. For a complete and accurate representation of the run command, docker inspect is still the preferred method. However, docker ps offers a convenient alternative for a quick glance at the running containers and their associated commands. As noted in the official Docker documentation, docker ps is designed for monitoring and managing container lifecycles. [^3^][Docker PS Documentation]

Alternative Methods and Considerations

While docker inspect, docker history, and docker ps are the primary methods for retrieving information about a container’s run command, there are alternative approaches and considerations to keep in mind. One approach is to examine the container’s logs, which might contain information about the startup process and the command that was executed. However, this method is not always reliable, as the logs may not contain the necessary information or may have been rotated.

Another consideration is the use of orchestration tools like Docker Compose or Kubernetes. These tools often define the run command in their configuration files, making it easier to track and manage. By examining the Compose file or Kubernetes deployment manifest, you can quickly determine the intended run command for a container. This approach is particularly useful in complex environments where containers are managed by orchestration tools. For example, a Docker Compose file might define the command to start a web server with specific environment variables and port mappings. This centralizes the configuration and makes it easier to understand how the container is supposed to be run.

Here are some key points to remember when trying to show the run command of a Docker container:

  • Use docker inspect for the most accurate and detailed information.
  • Consider docker history for understanding the image’s build process.
  • Use docker ps for a quick overview of running containers.

Here are the steps to finding the run command using docker inspect:

  1. Get the container ID or name using docker ps.
  2. Execute docker inspect -f ‘{{.Config.Cmd}}’ <container_id_or_name>.</container_id_or_name>
  3. Interpret the JSON array output to understand the command.
Infographic here
Featured Snippet Paragraph: The most reliable method to show the run command of a Docker container is by using the docker inspect command. By executing docker inspect -f '{{.Config.Cmd}}' , you can retrieve the exact command used to start the container, along with all its arguments, directly from the container's configuration.

FAQ

How can I find the command used to start a Docker container?
Use the docker inspect command with the -f '{{.Config.Cmd}}' option followed by the container ID or name.
What if the command is too long to display?
The docker inspect command provides the complete command, regardless of length. docker ps might truncate longer commands.
Can I see the command used to build the Docker image?
Yes, use the docker history command followed by the image name or ID to see the layers and commands used during the image build process.
Understanding how to find the run command of your Docker containers is a critical skill for any developer or system administrator working with containerized applications. Whether you're debugging an issue, replicating an environment, or simply trying to understand how a container is configured, the methods outlined above will provide you with the information you need. From using docker inspect for detailed configuration details to leveraging docker history for image lineage and docker ps for a quick overview, you now have a comprehensive toolkit at your disposal. [Improve your Docker skills](https://courthousezoological.com/n7sqp6kh?key=e6dd02bc5dbf461b97a9da08df84d31c) further and explore container orchestration for even greater control and efficiency.

Question & Answer :
I use a third party GUI (Synology Docker package) to setup a docker container. However, its limitation makes me need to run the container from the command line. (I want to map another host ip to bind the port)

Now, since there are lots of settings that already done, I would like to retrieve the original run command that start this container, then I can change the port mapping port to new one. eg. “docker run -p 80:8080 gitlab

I can’t find the way to do so, event use “docker inspect”, no such information provided.

Please provide some advice to solve this problem.

So how to reverse engineering docker run command?

There is a github repository which try to reverse engineering docker run command, but it is not perfect currently, version is 0.1.2. You should follow it for updating. Maybe one day you can use it to get correct run command with it.

$ sudo pip install runlike # run the ubuntu image $ docker run -ti ubuntu bash $ docker ps -a # suppose you get the container ID 1dfff2ba0226 # Run runlike to get the docker run command. $ runlike 1dfff2ba0226 docker run --name=elated_cray -t ubuntu bash 

Github repository: runlike

Updates:

Run without installing (Thanks @tilo)

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro \ assaflavie/runlike YOUR-CONTAINER 

or set alias and put it in your shell’s profile

alias runlike="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro assaflavie/runlike" docker ps runlike YOUR-CONTAINER