Updated on 2026-09-15 GMT+08:00
Logging In to a Container
Scenario
If you encounter unexpected problems when using a container, you can log in to the container to debug it.
Logging In to a Container Using CloudShell
- Log in to the CCE console.
- In the navigation pane, choose Workloads. Click the name of the target workload to view its pods.
- Locate the target pod and choose More > Remote Login in the Operation column. Figure 1 Accessing a container
- In the displayed dialog box, select the container you want to access and the command, and click OK. Figure 2 Selecting a container and login command
- You will be redirected to CloudShell. Then, kubectl is initialized and runs the kubectl exec command to log in to the container.
Wait for 5 to 10 seconds until the kubectl exec command is automatically executed.
Figure 3 CloudShell page
Logging In to a Container Using kubectl
- Use kubectl to connect to the cluster. For details, see Accessing a Cluster Using kubectl.
- Run the following command to view the created pod:
kubectl get pod
Example output:NAME READY STATUS RESTARTS AGE nginx-59d89cb66f-mhljr 1/1 Running 0 11m
- Query the container name in the pod.
kubectl get po nginx-59d89cb66f-mhljr -o jsonpath='{range .spec.containers[*]}{.name}{end}{"\n"}'The example output is as follows:container-1
- Run the following command to log in to the container-1 container in the nginx-59d89cb66f-mhljr pod:
kubectl exec -it nginx-59d89cb66f-mhljr -c container-1 -- /bin/sh
- To exit the container, run the exit command.
Helpful Links
- To learn more about workload parameters, see Creating a Workload.
- After a workload is created, you can upgrade it, edit its YAML file, and view its logs. For details, see Managing Workloads.
- If the workload fails to be created, rectify the fault by referring to Workload Exception Troubleshooting.
- Access an external network from a pod.
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot