Reputation: 4577
I'm trying to connect to a running container or start a new container in interactive mode with the bash shell -- not the sh shell. I want to run:
docker exec -it <container_name> /bin/bash
or
docker run -it <container_name> <image_name>
or
docker run -it <container_name> <image_name> /bin/bash
and get an interactive bash shell.
Per this post I've tried
SHELL ["/bin/bash", "-c"]
RUN ["/bin/bash", "-c", "echo I am now using bash!"]
But every time I try to run a container in interactive mode (docker run -it
or attach to a running container (docker exec -it
), I land in the sh
shell.
How can I get an interactive bash shell that is running inside a docker container?
FROM ubuntu
SHELL ["/bin/bash", "-c"]
Upvotes: 4
Views: 14230
Reputation: 263469
You are in fact running an interactive bash with commands like:
docker container run -it ubuntu /bin/bash
When you run bash in a docker container, that shell is in a container. So it won't have the command history from outside of the container, that history is maintained on the host filesystem. It also won't have your prompt, the PS1
variable is not automatically exported into the container's environment. And it won't have your .bashrc
configuration from your host, since that isn't inside the container. Instead you get a bash shell that is out of the box from a minimal ubuntu host.
Upvotes: 8