Nikita Kalitin
Nikita Kalitin

Reputation: 183

How to run /bin/bash in a docker container?

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

Upvotes: 5

Views: 21250

Answers (4)

yang1
yang1

Reputation: 31

docker exec -it container-name /bin/bash

Upvotes: 3

questionto42
questionto42

Reputation: 9502

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.

Upvotes: 0

Arnaud
Arnaud

Reputation: 15

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

And to connect use sudo docker attach awesome-container

Upvotes: 0

Paul
Paul

Reputation: 141819

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

Upvotes: 10

Related Questions