How Can I Get Into a Docker Container SHELL or BASH
March 6, 2023 2023-07-02 7:52How Can I Get Into a Docker Container SHELL or BASH
Once you build and deployed the docker container, we often need to look inside a running container to examine its current state or correct a problem. So the Docker providers a command with an option “docker exec” to run programs in containers that are already running.
The command started using docker exec only runs while the container’s primary process. Any command executed inside the container will run in the default working directory.
you need to find the container ID or name of the container you want to access. You can do this by running the following command,
$ docker ps
The above command will list all the running containers along with their IDs and names. m
The syntax of the Docker exec,
docker container exec -it [CONTAINER_ID] OR [CONTAINER_NAME] [/bin/sh] OR [/bin/bash] OR [sh] OR [bash]
You can run the following command to get into the container shell,
$ docker container exec -t apache_container sh
This command will open a shell session inside the container and allow you to interact with it. Once you work is completed inside the container, you can exit the shell by typing exit or pressing Ctrl + D.