{
	"id": "5acba0e9-a85b-452e-b891-9958789c9ef7",
	"created_at": "2026-04-06T00:21:56.567214Z",
	"updated_at": "2026-04-10T13:11:48.644063Z",
	"deleted_at": null,
	"sha1_hash": "35b163636080053e75d79a2f0fc8dd97b074eda5",
	"title": "Get a Shell to a Running Container",
	"llm_title": "",
	"authors": "",
	"file_creation_date": "0001-01-01T00:00:00Z",
	"file_modification_date": "0001-01-01T00:00:00Z",
	"file_size": 67454,
	"plain_text": "Get a Shell to a Running Container\r\nArchived: 2026-04-05 19:14:22 UTC\r\nThis page shows how to use kubectl exec to get a shell to a running container.\r\nBefore you begin\r\nYou need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate\r\nwith your cluster. It is recommended to run this tutorial on a cluster with at least two nodes that are not acting as\r\ncontrol plane hosts. If you do not already have a cluster, you can create one by using minikube or you can use one\r\nof these Kubernetes playgrounds:\r\niximiuz Labs\r\nKillercoda\r\nKodeKloud\r\nGetting a shell to a container\r\nIn this exercise, you create a Pod that has one container. The container runs the nginx image. Here is the\r\nconfiguration file for the Pod:\r\napiVersion: v1\r\nkind: Pod\r\nmetadata:\r\n name: shell-demo\r\nspec:\r\n volumes:\r\n - name: shared-data\r\n emptyDir: {}\r\n containers:\r\n - name: nginx\r\n image: nginx\r\n volumeMounts:\r\n - name: shared-data\r\n mountPath: /usr/share/nginx/html\r\n hostNetwork: true\r\n dnsPolicy: Default\r\nCreate the Pod:\r\nkubectl apply -f https://k8s.io/examples/application/shell-demo.yaml\r\nhttps://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/\r\nPage 1 of 4\n\nVerify that the container is running:\r\nkubectl get pod shell-demo\r\nGet a shell to the running container:\r\nkubectl exec --stdin --tty shell-demo -- /bin/bash\r\nNote:\r\nThe double dash ( -- ) separates the arguments you want to pass to the command from the kubectl arguments.\r\nIn your shell, list the root directory:\r\n# Run this inside the container\r\nls /\r\nIn your shell, experiment with other commands. Here are some examples:\r\n# You can run these example commands inside the container\r\nls /\r\ncat /proc/mounts\r\ncat /proc/1/maps\r\napt-get update\r\napt-get install -y tcpdump\r\ntcpdump\r\napt-get install -y lsof\r\nlsof\r\napt-get install -y procps\r\nps aux\r\nps aux | grep nginx\r\nWriting the root page for nginx\r\nLook again at the configuration file for your Pod. The Pod has an emptyDir volume, and the container mounts\r\nthe volume at /usr/share/nginx/html .\r\nIn your shell, create an index.html file in the /usr/share/nginx/html directory:\r\n# Run this inside the container\r\necho 'Hello shell demo' \u003e /usr/share/nginx/html/index.html\r\nIn your shell, send a GET request to the nginx server:\r\nhttps://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/\r\nPage 2 of 4\n\n# Run this in the shell inside your container\r\napt-get update\r\napt-get install curl\r\ncurl http://localhost/\r\nThe output shows the text that you wrote to the index.html file:\r\nHello shell demo\r\nWhen you are finished with your shell, enter exit .\r\nexit # To quit the shell in the container\r\nRunning individual commands in a container\r\nIn an ordinary command window, not your shell, list the environment variables in the running container:\r\nkubectl exec shell-demo -- env\r\nExperiment with running other commands. Here are some examples:\r\nkubectl exec shell-demo -- ps aux\r\nkubectl exec shell-demo -- ls /\r\nkubectl exec shell-demo -- cat /proc/1/mounts\r\nOpening a shell when a Pod has more than one container\r\nIf a Pod has more than one container, use --container or -c to specify a container in the kubectl exec\r\ncommand. For example, suppose you have a Pod named my-pod, and the Pod has two containers named main-app\r\nand helper-app. The following command would open a shell to the main-app container.\r\nkubectl exec -i -t my-pod --container main-app -- /bin/bash\r\nNote:\r\nThe short options -i and -t are the same as the long options --stdin and --tty\r\nWhat's next\r\nRead about kubectl exec\r\nhttps://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/\r\nPage 3 of 4\n\nLast modified September 19, 2023 at 11:12 PM PST: fix: update deprecated command (448734c716)\r\nSource: https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/\r\nhttps://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/\r\nPage 4 of 4",
	"extraction_quality": 1,
	"language": "EN",
	"sources": [
		"MITRE"
	],
	"origins": [
		"web"
	],
	"references": [
		"https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/"
	],
	"report_names": [
		"get-shell-running-container"
	],
	"threat_actors": [],
	"ts_created_at": 1775434916,
	"ts_updated_at": 1775826708,
	"ts_creation_date": 0,
	"ts_modification_date": 0,
	"files": {
		"pdf": "https://archive.orkl.eu/35b163636080053e75d79a2f0fc8dd97b074eda5.pdf",
		"text": "https://archive.orkl.eu/35b163636080053e75d79a2f0fc8dd97b074eda5.txt",
		"img": "https://archive.orkl.eu/35b163636080053e75d79a2f0fc8dd97b074eda5.jpg"
	}
}