How to run /bin/bash in a docker container?
Asked Answered
V

4

5

How to run /bin/bash in a docker container that was started with the -d option, for example:

sudo docker run -P --name test-cnt3 -d base-tst:0.1? 

I really need a console in the container and I already despaired of running it

Vauban answered 5/4, 2018 at 7:18 Comment(0)
M
10

Use docker exec to run a command in an already running container, use -it to create a new interactive pseudo-TTY:

docker exec -it test-cnt3 /bin/bash
Magnetism answered 5/4, 2018 at 7:21 Comment(0)
J
3
docker exec -it container-name /bin/bash
Joijoice answered 28/12, 2021 at 11:20 Comment(0)
P
0

If you use docker-composer or Dockerfile look at Entrypoint & CMD

And to connect use sudo docker attach awesome-container

Pooh answered 5/4, 2018 at 7:25 Comment(0)
A
0

In my case, docker exec -it test /bin/bash gave me

Error response from daemon: Container f63bba8... is not running

When I tried

docker start test

the container started, but trying exec again threw the same error as before.

In the end, I had to enter

docker run -it test /bin/bash

This starts the bash right before the container stops.

Alain answered 20/3, 2021 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.