{"id":15453,"date":"2024-04-27T12:07:08","date_gmt":"2024-04-27T08:37:08","guid":{"rendered":"https:\/\/www.itpiran.net\/blog\/?p=15453"},"modified":"2024-04-27T12:07:08","modified_gmt":"2024-04-27T08:37:08","slug":"how-to-use-docker-exec-to-run-commands-in-a-docker-container","status":"publish","type":"post","link":"https:\/\/www.itpiran.net\/blog\/en\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/","title":{"rendered":"How to use docker exec to run commands in a Docker Container"},"content":{"rendered":"<h2 id=\"%d9%85%d9%82%d8%af%d9%85%d9%87\">Introduction<\/h2>\n<p>Docker is a containerization tool that helps developers create and manage portable, Linux-compatible containers.<\/p>\n<p>When developing or deploying containers, you often need to look inside a running container to check its current state or troubleshoot a problem. For this purpose, Docker provides the docker exec command to execute applications in running containers.<\/p>\n<p>In this tutorial, we will learn about the docker exec command and how to use it to run commands and get an interactive shell in a Docker container.<\/p>\n<h5 id=\"%d9%be%db%8c%d8%b4-%d9%86%db%8c%d8%a7%d8%b2%d9%87%d8%a7\">Prerequisites<\/h5>\n<p>This tutorial assumes that you have already installed Docker and your user has permission to run docker. If you need to run docker as root user, please remember to add sudo to the commands in this tutorial.<\/p>\n<h2 id=\"%d8%b1%d8%a7%d9%87-%d8%a7%d9%86%d8%af%d8%a7%d8%b2%db%8c-%da%a9%d8%a7%d9%86%d8%aa%d8%a7%db%8c%d9%86%d8%b1-%d8%aa%d8%b3%d8%aa\">Launching a test container<\/h2>\n<p>To use the docker exec command, you need a running Docker container. If you don&#039;t already have one, start a test container with the following docker exec command:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker run -d --name container-name alpine watch \"date &gt;&gt; \/var\/log\/date.log\"<\/code><\/pre>\n<\/div>\n<p>This command creates a new Docker container from the official Alpine image. This is a popular Linux container image that uses Alpine Linux, a lightweight and minimal Linux distribution.<\/p>\n<p>We use -d to detach the container from the terminal and run it in the background. --name container-name names the container. You can choose any name you like here or leave this out entirely to have Docker automatically generate a unique name for the new container.<\/p>\n<p>Next we have alpine which specifies the image we want to use for the container.<\/p>\n<p>And finally, we have \u201cdate &gt;&gt; \/var\/log\/date.log\u201d. This is the command we want to run in the container. By default, the clock will run the command you give it every two seconds. The command that the clock will run in this case is date &gt;&gt; \/var\/log\/date.log. date prints the current date and time, like this:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>OutputFri Jul 23 14:57:05 UTC 2021<\/code><\/pre>\n<\/div>\n<p>The &gt;&gt; \/var\/log\/date.log section redirects the output of the date command and appends it to the file \/var\/log\/date.log. Every two seconds a new line is appended to the file, and after a few seconds it will look something like this:<\/p>\n<pre><\/pre>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\nFri Jul 23 15:00:26 UTC 2021\r\nFri Jul 23 15:00:28 UTC 2021\r\nFri Jul 23 15:00:30 UTC 2021\r\nFri Jul 23 15:00:32 UTC 2021\r\nFri Jul 23 15:00:34 UTC 2021<\/code><\/pre>\n<\/div>\n<p>Next, we&#039;ll learn how to find the name of Docker containers. This is useful if you already have a container you&#039;re targeting, but aren&#039;t sure what it&#039;s called.<\/p>\n<h2 id=\"%d9%be%db%8c%d8%af%d8%a7-%da%a9%d8%b1%d8%af%d9%86-%d9%86%d8%a7%d9%85-%da%a9%d8%a7%d9%86%d8%aa%db%8c%d9%86%d8%b1-%d8%af%d8%a7%da%a9%d8%b1\">Finding the Docker container name<\/h2>\n<p>We need to provide docker exec with the name (or container ID) of the container we want to work with. We can find this information using the docker ps command:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker ps<\/code><\/pre>\n<\/div>\n<p>This command lists all Docker containers running on the server and provides some high-level information about them:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\r\n76aded7112d4 alpine \"watch 'date &gt;&gt; \/var\u2026\" 11 seconds ago Up 10 seconds container-name<\/code><\/pre>\n<\/div>\n<p>In this example, the container ID and name are highlighted. You can use either to tell docker exec which container to use.<\/p>\n<p>If you want to change the name of your container, use the docker rename command:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker rename container-name new-name<\/code><\/pre>\n<\/div>\n<p>Next, we will run several examples of using docker exec to execute commands in a Docker container.<\/p>\n<h2 id=\"%d8%a7%d8%ac%d8%b1%d8%a7%db%8c-%db%8c%da%a9-%d9%be%d9%88%d8%b3%d8%aa%d9%87-%d8%aa%d8%b9%d8%a7%d9%85%d9%84%db%8c-%d8%af%d8%b1-%db%8c%da%a9-%d8%af%d8%a7%da%a9%d8%b1-%da%a9%d8%a7%d9%86%d8%aa%db%8c%d9%86\">Running an interactive shell in a Docker container<\/h2>\n<p>If you need to launch an interactive shell inside a Docker container, perhaps to explore the file system or debug running processes, use docker exec with the -i and -t flags.<\/p>\n<p>The -i flag keeps the input to the container open, and the -t flag creates a pseudo-terminal that the shell can connect to. These flags can be combined as follows:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker exec -it container-name sh<\/code><\/pre>\n<\/div>\n<p>This will run the shell in the specified container and give you an initial shell prompt. To exit the container, type exit and press ENTER:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>exit<\/code><\/pre>\n<\/div>\n<p>If your container image includes a more advanced shell like bash, you can replace sh with bash above.<\/p>\n<h2 id=\"%d8%a7%d8%ac%d8%b1%d8%a7%db%8c-%db%8c%da%a9-%d9%81%d8%b1%d9%85%d8%a7%d9%86-%d8%ba%db%8c%d8%b1-%d8%aa%d8%b9%d8%a7%d9%85%d9%84%db%8c-%d8%af%d8%b1-%db%8c%da%a9-%d8%af%d8%a7%da%a9%d8%b1-%da%a9%d8%a7%d9%86\">Running a non-interactive command in a Docker container<\/h2>\n<p>If you need to run a command inside a running container, but don&#039;t need to interact, use the docker exec command without any flags:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker exec container-name tail \/var\/log\/date.log<\/code><\/pre>\n<\/div>\n<p>This command will run tail \/var\/log\/date.log on the container container name and print the results. By default, the tail command prints the last ten lines of a file. If you run the test container we set up in the first section, you will see something like this:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\nMon Jul 26 14:39:33 UTC 2021\r\nMon Jul 26 14:39:35 UTC 2021\r\nMon Jul 26 14:39:37 UTC 2021\r\nMon Jul 26 14:39:39 UTC 2021\r\nMon Jul 26 14:39:41 UTC 2021\r\nMon Jul 26 14:39:43 UTC 2021\r\nMon Jul 26 14:39:45 UTC 2021\r\nMon Jul 26 14:39:47 UTC 2021\r\nMon Jul 26 14:39:49 UTC 2021\r\nMon Jul 26 14:39:51 UTC 2021<\/code><\/pre>\n<\/div>\n<p>This is essentially the same as opening an interactive shell for the Docker container (as was done in the previous step with docker exec -it container-name sh ) and then running the tail \/var\/log\/date.log command. However, instead of opening a shell, running the command, and then closing the shell, this command returns the same output in a single command without opening a pseudo-terminal.<\/p>\n<h2 id=\"%d8%a7%d8%ac%d8%b1%d8%a7%db%8c-%d8%af%d8%b3%d8%aa%d9%88%d8%b1%d8%a7%d8%aa-%d8%af%d8%b1-%db%8c%da%a9-%d9%81%d9%87%d8%b1%d8%b3%d8%aa-%d8%ac%d8%a7%db%8c%da%af%d8%b2%db%8c%d9%86-%d8%af%d8%b1-%db%8c%da%a9\">Running commands in an alternate directory in a Docker container<\/h2>\n<p>To run a command in a specific directory of your container, use the \u2013workdir flag to specify the directory:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker exec --workdir \/tmp container-name pwd<\/code><\/pre>\n<\/div>\n<p>This example command sets the \/tmp directory as the working directory, then runs the pwd command, which prints the current working directory:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\n\/tmp<\/code><\/pre>\n<\/div>\n<p>The pwd command has confirmed that the working directory is \/tmp.<\/p>\n<h2 id=\"%d8%a7%d8%ac%d8%b1%d8%a7%db%8c-%d8%af%d8%b3%d8%aa%d9%88%d8%b1%d8%a7%d8%aa-%d8%a8%d9%87-%d8%b9%d9%86%d9%88%d8%a7%d9%86-%db%8c%da%a9-%da%a9%d8%a7%d8%b1%d8%a8%d8%b1-%d9%85%d8%aa%d9%81%d8%a7%d9%88%d8%aa\">Running commands as a different user in a Docker container<\/h2>\n<p>To run a command as a different user inside your container, add the --user flag:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker exec --user guest container-name whoami<\/code><\/pre>\n<\/div>\n<p>This uses the guest user to run the whoami command in the container. The whoami command prints the current username of the user:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\nguest<\/code><\/pre>\n<\/div>\n<\/div>\n<p>The whoami command confirms that the current user of the container is the guest.<\/p>\n<h2 id=\"%d8%a7%d9%86%d8%aa%d9%82%d8%a7%d9%84-%d9%85%d8%aa%d8%ba%db%8c%d8%b1%d9%87%d8%a7%db%8c-%d9%85%d8%ad%db%8c%d8%b7%db%8c-%d8%a8%d9%87-%da%a9%d8%a7%d9%86%d8%aa%db%8c%d9%86%d8%b1-%d8%af%d8%a7%da%a9%d8%b1\">Passing environment variables to a Docker container<\/h2>\n<p>Sometimes it is necessary to pass environment variables to a container along with the run command. The -e flag allows you to specify an environment variable:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker exec -e TEST=sammy container-name env<\/code><\/pre>\n<\/div>\n<p>This command sets the TEST environment variable to sammy, then runs the env command inside the container. The env command then prints all the environment variables:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin\r\nHOSTNAME=76aded7112d4\r\nTEST=sammy\r\nHOME=\/root<\/code><\/pre>\n<\/div>\n<\/div>\n<p>The TEST variable is set to sammy.<\/p>\n<p>To set multiple variables, repeat the -e flag for each:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker exec -e TEST=sammy -e ENVIRONMENT=prod container-name env<\/code><\/pre>\n<\/div>\n<p>If you want to pass a file full of environment variables, you can do so with the \u2013env-file flag.<\/p>\n<p>First, create the file with a text editor. We&#039;ll open a new file with nano here, but you can use any editor you&#039;re comfortable with:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>nano .env<\/code><\/pre>\n<\/div>\n<p>We use .env as the file name because it is a popular standard for using these types of files to manage information outside of version control.<\/p>\n<p>Write your KEY=value variables in the file, one per line, as shown below:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>TEST=sammy\r\nENVIRONMENT=prod<\/code><\/pre>\n<\/div>\n<p>Save and close the file. To save the file and exit nano, press CTRL+O, then ENTER to save, then CTRL+X to exit.<\/p>\n<p>Now run the docker exec command and specify the correct file name after \u2013env-file:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker exec --env-file .env container-name env<\/code><\/pre>\n<\/div>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Output\r\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin\r\nHOSTNAME=76aded7112d4\r\nTEST=sammy\r\nENVIRONMENT=prod\r\nHOME=\/root<\/code><\/pre>\n<\/div>\n<p>Two variables are set in the file.<\/p>\n<p>You can specify multiple files using multiple \u2013env-file flags. If the variables in the files overlap, whichever file is listed in the last command will override the previous files.<\/p>\n<h2 id=\"%d8%ae%d8%b7%d8%a7%d9%87%d8%a7%db%8c-%d8%b1%d8%a7%db%8c%d8%ac\">Common errors<\/h2>\n<p>When using the docker exec command, you may encounter a few common errors:<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Error: No such container: container-name\r\n<\/code><\/pre>\n<\/div>\n<p>The No such container error means that the specified container does not exist and may indicate a misspelling of the container name. Use docker ps to list your running containers and double-check the name.<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Error response from daemon: Container 2a94aae70ea5dc92a12e30b13d0613dd6ca5919174d73e62e29cb0f79db6e4ab is not running\r\n<\/code><\/pre>\n<\/div>\n<p>This message running means that the container exists but is stopped. You can start the container with docker start container-name<\/p>\n<div class=\"hcb_wrap\" data-no-translation=\"\" data-no-auto-translation=\"\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>Error response from daemon: Container container-name is paused, unpause the container before exec\r\n<\/code><\/pre>\n<\/div>\n<p>The error Container is paused explains the problem well. Before continuing, you need to unpause the container with docker unpause container-name .<\/p>\n<h2 id=\"%d9%86%d8%aa%db%8c%d8%ac%d9%87\">Result<\/h2>\n<p>In this tutorial we learned how to execute commands in a running Docker container, along with some command line options when doing so.<\/p>","protected":false},"excerpt":{"rendered":"Introduction Docker is a containerization tool that helps developers create portable, Linux-compatible containers\u2026","protected":false},"author":1,"featured_media":15454,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_yoast_wpseo_focuskw":"","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"","_yoast_wpseo_canonical":"","_yoast_wpseo_opengraph-description":"","_yoast_wpseo_opengraph-image":"","_yoast_wpseo_twitter-description":"","_yoast_wpseo_twitter-image":"","_yoast_wpseo_focuskeywords":"","_yoast_wpseo_primary_category":"193","footnotes":""},"categories":[193,363],"tags":[424,346],"class_list":{"0":"post-15453","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-tutorials","8":"category-programming","9":"tag-container","10":"tag-docker"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 docker exec \u0628\u0631\u0627\u06cc \u0627\u062c\u0631\u0627\u06cc \u062f\u0633\u062a\u0648\u0631\u0627\u062a \u062f\u0631 \u06cc\u06a9 Docker Container - \u0628\u0644\u0627\u06af ITPiran<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.itpiran.net\/blog\/en\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 docker exec \u0628\u0631\u0627\u06cc \u0627\u062c\u0631\u0627\u06cc \u062f\u0633\u062a\u0648\u0631\u0627\u062a \u062f\u0631 \u06cc\u06a9 Docker Container - \u0628\u0644\u0627\u06af ITPiran\" \/>\n<meta property=\"og:description\" content=\"\u0645\u0642\u062f\u0645\u0647 Docker \u06cc\u06a9 \u0627\u0628\u0632\u0627\u0631 \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631\u06cc\u200c\u0633\u0627\u0632\u06cc \u0627\u0633\u062a \u06a9\u0647 \u0628\u0647 \u062a\u0648\u0633\u0639\u0647\u200c\u062f\u0647\u0646\u062f\u06af\u0627\u0646 \u06a9\u0645\u06a9 \u0645\u06cc\u200c\u06a9\u0646\u062f \u062a\u0627 \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631\u0647\u0627\u06cc \u0642\u0627\u0628\u0644 \u062d\u0645\u0644 \u0648 \u0633\u0627\u0632\u06af\u0627\u0631 \u0644\u06cc\u0646\u0648\u06a9\u0633&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.itpiran.net\/blog\/en\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/\" \/>\n<meta property=\"og:site_name\" content=\"\u0628\u0644\u0627\u06af ITPiran\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-27T08:37:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.itpiran.net\/2024\/04\/27120556\/docker1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1793\" \/>\n\t<meta property=\"og:image:height\" content=\"1110\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/person\\\/04ed27b919baca468a2273f8e4318f81\"},\"headline\":\"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 docker exec \u0628\u0631\u0627\u06cc \u0627\u062c\u0631\u0627\u06cc \u062f\u0633\u062a\u0648\u0631\u0627\u062a \u062f\u0631 \u06cc\u06a9 Docker Container\",\"datePublished\":\"2024-04-27T08:37:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/\"},\"wordCount\":140,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/04\\\/27120556\\\/docker1.jpg\",\"keywords\":[\"container\",\"Docker\"],\"articleSection\":[\"\u0622\u0645\u0648\u0632\u0634\u06cc\",\"\u0628\u0631\u0646\u0627\u0645\u0647 \u0646\u0648\u06cc\u0633\u06cc\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/\",\"name\":\"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 docker exec \u0628\u0631\u0627\u06cc \u0627\u062c\u0631\u0627\u06cc \u062f\u0633\u062a\u0648\u0631\u0627\u062a \u062f\u0631 \u06cc\u06a9 Docker Container - \u0628\u0644\u0627\u06af ITPiran\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/04\\\/27120556\\\/docker1.jpg\",\"datePublished\":\"2024-04-27T08:37:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/#primaryimage\",\"url\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/04\\\/27120556\\\/docker1.jpg\",\"contentUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2024\\\/04\\\/27120556\\\/docker1.jpg\",\"width\":1793,\"height\":1110},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/tutorials\\\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u0622\u0645\u0648\u0632\u0634\u06cc\",\"item\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/category\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 docker exec \u0628\u0631\u0627\u06cc \u0627\u062c\u0631\u0627\u06cc \u062f\u0633\u062a\u0648\u0631\u0627\u062a \u062f\u0631 \u06cc\u06a9 Docker Container\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/\",\"name\":\"\u0628\u0644\u0627\u06af ITPiran\",\"description\":\"\u0627\u062e\u0628\u0627\u0631 \u0648 \u0645\u0642\u0627\u0644\u0627\u062a \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#organization\",\"name\":\"\u0628\u0644\u0627\u06af \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646\",\"alternateName\":\"ITPIran Blog\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/cdn.itpiran.net\\\/2023\\\/12\\\/27150508\\\/cropped-ITPIRAN-BLOG-LOGO-2.png\",\"contentUrl\":\"https:\\\/\\\/cdn.itpiran.net\\\/2023\\\/12\\\/27150508\\\/cropped-ITPIRAN-BLOG-LOGO-2.png\",\"width\":512,\"height\":512,\"caption\":\"\u0628\u0644\u0627\u06af \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646\"},\"image\":{\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/#\\\/schema\\\/person\\\/04ed27b919baca468a2273f8e4318f81\",\"name\":\"admin\",\"url\":\"https:\\\/\\\/www.itpiran.net\\\/blog\\\/en\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use docker exec to run commands in a Docker Container - ITPiran Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.itpiran.net\/blog\/en\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/","og_locale":"en_US","og_type":"article","og_title":"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 docker exec \u0628\u0631\u0627\u06cc \u0627\u062c\u0631\u0627\u06cc \u062f\u0633\u062a\u0648\u0631\u0627\u062a \u062f\u0631 \u06cc\u06a9 Docker Container - \u0628\u0644\u0627\u06af ITPiran","og_description":"\u0645\u0642\u062f\u0645\u0647 Docker \u06cc\u06a9 \u0627\u0628\u0632\u0627\u0631 \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631\u06cc\u200c\u0633\u0627\u0632\u06cc \u0627\u0633\u062a \u06a9\u0647 \u0628\u0647 \u062a\u0648\u0633\u0639\u0647\u200c\u062f\u0647\u0646\u062f\u06af\u0627\u0646 \u06a9\u0645\u06a9 \u0645\u06cc\u200c\u06a9\u0646\u062f \u062a\u0627 \u06a9\u0627\u0646\u062a\u06cc\u0646\u0631\u0647\u0627\u06cc \u0642\u0627\u0628\u0644 \u062d\u0645\u0644 \u0648 \u0633\u0627\u0632\u06af\u0627\u0631 \u0644\u06cc\u0646\u0648\u06a9\u0633&hellip;","og_url":"https:\/\/www.itpiran.net\/blog\/en\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/","og_site_name":"\u0628\u0644\u0627\u06af ITPiran","article_published_time":"2024-04-27T08:37:08+00:00","og_image":[{"width":1793,"height":1110,"url":"https:\/\/cdn.itpiran.net\/2024\/04\/27120556\/docker1.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/#article","isPartOf":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/"},"author":{"name":"admin","@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/person\/04ed27b919baca468a2273f8e4318f81"},"headline":"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 docker exec \u0628\u0631\u0627\u06cc \u0627\u062c\u0631\u0627\u06cc \u062f\u0633\u062a\u0648\u0631\u0627\u062a \u062f\u0631 \u06cc\u06a9 Docker Container","datePublished":"2024-04-27T08:37:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/"},"wordCount":140,"commentCount":0,"publisher":{"@id":"https:\/\/www.itpiran.net\/blog\/#organization"},"image":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.itpiran.net\/2024\/04\/27120556\/docker1.jpg","keywords":["container","Docker"],"articleSection":["\u0622\u0645\u0648\u0632\u0634\u06cc","\u0628\u0631\u0646\u0627\u0645\u0647 \u0646\u0648\u06cc\u0633\u06cc"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/","url":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/","name":"How to use docker exec to run commands in a Docker Container - ITPiran Blog","isPartOf":{"@id":"https:\/\/www.itpiran.net\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/#primaryimage"},"image":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.itpiran.net\/2024\/04\/27120556\/docker1.jpg","datePublished":"2024-04-27T08:37:08+00:00","breadcrumb":{"@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/#primaryimage","url":"https:\/\/cdn.itpiran.net\/2024\/04\/27120556\/docker1.jpg","contentUrl":"https:\/\/cdn.itpiran.net\/2024\/04\/27120556\/docker1.jpg","width":1793,"height":1110},{"@type":"BreadcrumbList","@id":"https:\/\/www.itpiran.net\/blog\/tutorials\/how-to-use-docker-exec-to-run-commands-in-a-docker-container\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.itpiran.net\/blog\/"},{"@type":"ListItem","position":2,"name":"\u0622\u0645\u0648\u0632\u0634\u06cc","item":"https:\/\/www.itpiran.net\/blog\/category\/tutorials\/"},{"@type":"ListItem","position":3,"name":"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 docker exec \u0628\u0631\u0627\u06cc \u0627\u062c\u0631\u0627\u06cc \u062f\u0633\u062a\u0648\u0631\u0627\u062a \u062f\u0631 \u06cc\u06a9 Docker Container"}]},{"@type":"WebSite","@id":"https:\/\/www.itpiran.net\/blog\/#website","url":"https:\/\/www.itpiran.net\/blog\/","name":"ITPiran Blog","description":"Iranian Sustainable Trade News and Articles","publisher":{"@id":"https:\/\/www.itpiran.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.itpiran.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.itpiran.net\/blog\/#organization","name":"Sustainable Iranian Business Blog","alternateName":"ITPIran Blog","url":"https:\/\/www.itpiran.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdn.itpiran.net\/2023\/12\/27150508\/cropped-ITPIRAN-BLOG-LOGO-2.png","contentUrl":"https:\/\/cdn.itpiran.net\/2023\/12\/27150508\/cropped-ITPIRAN-BLOG-LOGO-2.png","width":512,"height":512,"caption":"\u0628\u0644\u0627\u06af \u062a\u062c\u0627\u0631\u062a \u067e\u0627\u06cc\u062f\u0627\u0631 \u0627\u06cc\u0631\u0627\u0646\u06cc\u0627\u0646"},"image":{"@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.itpiran.net\/blog\/#\/schema\/person\/04ed27b919baca468a2273f8e4318f81","name":"admin","url":"https:\/\/www.itpiran.net\/blog\/en\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/posts\/15453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/comments?post=15453"}],"version-history":[{"count":2,"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/posts\/15453\/revisions"}],"predecessor-version":[{"id":15456,"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/posts\/15453\/revisions\/15456"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/media\/15454"}],"wp:attachment":[{"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/media?parent=15453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/categories?post=15453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itpiran.net\/blog\/en\/wp-json\/wp\/v2\/tags?post=15453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}