{
	"id": "dca84ff1-be6a-4902-a7f5-a372555d4666",
	"created_at": "2026-04-06T00:11:23.299935Z",
	"updated_at": "2026-04-10T03:21:18.507341Z",
	"deleted_at": null,
	"sha1_hash": "9db0b33cbfefa8aab0562696f9f17dc0047bedbe",
	"title": "docker container exec",
	"llm_title": "",
	"authors": "",
	"file_creation_date": "0001-01-01T00:00:00Z",
	"file_modification_date": "0001-01-01T00:00:00Z",
	"file_size": 61593,
	"plain_text": "docker container exec\r\nBy Docker Inc\r\nPublished: 2001-01-01 · Archived: 2026-04-05 12:43:17 UTC\r\nDescription Execute a command in a running container\r\nUsage\r\ndocker container exec [OPTIONS] CONTAINER\r\nCOMMAND [ARG...]\r\nAliases\r\nAn alias is a short or memorable alternative for a\r\nlonger command.\r\ndocker exec\r\nThe docker exec command runs a new command in a running container.\r\nThe command you specify with docker exec only runs while the container's primary process ( PID 1 ) is\r\nrunning, and it isn't restarted if the container is restarted.\r\nThe command runs in the default working directory of the container.\r\nThe command must be an executable. A chained or a quoted command doesn't work.\r\nThis works: docker exec -it my_container sh -c \"echo a \u0026\u0026 echo b\"\r\nThis doesn't work: docker exec -it my_container \"echo a \u0026\u0026 echo b\"\r\nOption Default Description\r\n-d, --detach Detached mode: run command in the background\r\n--detach-keys Override the key sequence for detaching a container\r\n-e, --env API 1.25+ Set environment variables\r\n--env-file API 1.25+ Read in a file of environment variables\r\n-i, --interactive Keep STDIN open even if not attached\r\n--privileged Give extended privileges to the command\r\n-t, --tty Allocate a pseudo-TTY\r\n-u, --user Username or UID (format: \u003cname|uid\u003e[:\u003cgroup|gid\u003e] )\r\n-w, --workdir API 1.35+ Working directory inside the container\r\nhttps://docs.docker.com/engine/reference/commandline/exec/\r\nPage 1 of 2\n\nRun docker exec on a running container\r\nFirst, start a container.\r\nThis creates and starts a container named mycontainer from an alpine image with an sh shell as its main\r\nprocess. The -d option (shorthand for --detach ) sets the container to run in the background, in detached mode,\r\nwith a pseudo-TTY attached ( -t ). The -i option is set to keep STDIN attached ( -i ), which prevents the\r\nsh process from exiting immediately.\r\nNext, execute a command on the container.\r\nThis creates a new file /tmp/execWorks inside the running container mycontainer , in the background.\r\nNext, execute an interactive sh shell on the container.\r\nThis starts a new shell session in the container mycontainer .\r\nSet environment variables for the exec process (--env, -e)\r\nNext, set environment variables in the current bash session.\r\nThe docker exec command inherits the environment variables that are set at the time the container is created.\r\nUse the --env (or the -e shorthand) to override global environment variables, or to set additional environment\r\nvariables for the process started by docker exec .\r\nThe following example creates a new shell session in the container mycontainer , with environment variables\r\n$VAR_A set to 1 , and $VAR_B set to 2 . These environment variables are only valid for the sh process\r\nstarted by that docker exec command, and aren't available to other processes running inside the container.\r\nEscalate container privileges (--privileged)\r\nSee docker run --privileged .\r\nSet the working directory for the exec process (--workdir, -w)\r\nBy default docker exec command runs in the same working directory set when the container was created.\r\nYou can specify an alternative working directory for the command to execute using the --workdir option (or the\r\n-w shorthand):\r\nTry to run docker exec on a paused container\r\nIf the container is paused, then the docker exec command fails with an error:\r\nSource: https://docs.docker.com/engine/reference/commandline/exec/\r\nhttps://docs.docker.com/engine/reference/commandline/exec/\r\nPage 2 of 2",
	"extraction_quality": 1,
	"language": "EN",
	"sources": [
		"MITRE"
	],
	"references": [
		"https://docs.docker.com/engine/reference/commandline/exec/"
	],
	"report_names": [
		"exec"
	],
	"threat_actors": [],
	"ts_created_at": 1775434283,
	"ts_updated_at": 1775791278,
	"ts_creation_date": 0,
	"ts_modification_date": 0,
	"files": {
		"pdf": "https://archive.orkl.eu/9db0b33cbfefa8aab0562696f9f17dc0047bedbe.pdf",
		"text": "https://archive.orkl.eu/9db0b33cbfefa8aab0562696f9f17dc0047bedbe.txt",
		"img": "https://archive.orkl.eu/9db0b33cbfefa8aab0562696f9f17dc0047bedbe.jpg"
	}
}