📜  docker exit - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:14:45.664000             🧑  作者: Mango

Docker Exit - Shell/Bash

Introduction

Docker is a powerful tool that allows users to create, run, and manage containers. However, as a programmer, you may encounter a situation where you need to exit a Docker container in the Shell/Bash command line. This guide will detail the steps to exit a Docker container in Shell/Bash.

Exit a Docker container

To exit a Docker container in Shell/Bash, you can use the exit command followed by the container ID or name.

Using Container ID
  1. First, use the docker ps command to list all running containers and their ID:
$ docker ps
CONTAINER ID   IMAGE           COMMAND      CREATED         STATUS         PORTS     NAMES
c02751d3c360   nginx:latest    "/nginx..."  5 minutes ago   Up 5 minutes   80/tcp    nginx_container
  1. Copy the container ID of the container that you want to exit.

  2. Now, use the following command to exit the container:

$ docker container exit [container ID]
Using Container Name
  1. You can also use the container name to exit the container:
$ docker container exit [container name]
Conclusion

Exiting a Docker container in Shell/Bash is a simple process that can be accomplished using the exit command followed by the container ID or name. These commands provide a quick and efficient way to exit a container from the Shell/Bash command line.