Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Docker 'run' command to start an interactive BaSH session
# Assuming an Ubuntu Docker image
$ docker run -it <image> /bin/bash
@boyney123

This comment has been minimized.

Copy link

boyney123 commented Jan 4, 2017

Thanks

@arjabbar

This comment has been minimized.

Copy link

arjabbar commented Jan 28, 2017

You can also do it without the /bin/ part
docker run -it ubuntu bash
or if you literally need nothing else but bash...
docker run -it bash

@jghaines

This comment has been minimized.

Copy link

jghaines commented Feb 13, 2017

This won't work if your image has a defined ENTRYPOINT. For these cases use:
docker run -it --entrypoint /bin/bash <image>

@sanbor

This comment has been minimized.

Copy link

sanbor commented Feb 22, 2017

docker run -it stands for docker run --interactive --tty. Found this info it in man docker-run.

@augnustin

This comment has been minimized.

Copy link

augnustin commented Mar 24, 2017

👍
It could be also nice to share current folder between contexts.

@augnustin

This comment has been minimized.

Copy link

augnustin commented Mar 24, 2017

docker run -v $(pwd):/root -it node /bin/bash

@dkowsley

This comment has been minimized.

Copy link

dkowsley commented Jan 4, 2018

@arjabbar /bin/bash and bash are not always the same thing. The former is a direct reference to an executable and the latter is detected by searching $PATH for an executable with the name bash.

As for the second line: docker run -it bash does not run bash inside of your image; it downloads the bash:latest image and runs it. It is syntactically equivalent to running docker run -it --entrypoint /usr/local/bin/bash bash

@johngrabner

This comment has been minimized.

Copy link

johngrabner commented Jan 19, 2018

Is there a form of this I can use to log into github as part of the "docker build ."?
My node project uses private npm packages stored in githib. So my build dies with
npm ERR! /usr/bin/git ls-remote -h -t https://github.com/johngrabner/purple_shared_enums_cloud_and_charger.git
npm ERR! remote: Invalid username or password.

@fusir

This comment has been minimized.

Copy link

fusir commented Mar 31, 2018

I find that when I run docker run -it --entrypoint bash <image> that it does not save any of my changes.

@PRElias

This comment has been minimized.

Copy link

PRElias commented Jun 7, 2018

I think it never saves your changes because they are made to the container and not the image itself.
You can save it as a new image like this:
$ docker commit <container_id> new_image_name:tag_name(optional)

As you are on bash, you have to skip it to root or use another terminal (take a note of your container ID)

@berezovskyi

This comment has been minimized.

Copy link

berezovskyi commented Jul 17, 2018

docker run -it --entrypoint /bin/sh for the images w/o bash.

@Andres-Hack

This comment has been minimized.

Copy link

Andres-Hack commented Oct 10, 2018

docker run -it --entrypoint /bin/sh

@abhidp

This comment has been minimized.

Copy link

abhidp commented Oct 29, 2018

docker run -it --entrypoint /bin/sh for the images w/o bash.

thank you.. ..you are a savior

@gpetz

This comment has been minimized.

Copy link

gpetz commented Mar 6, 2019

if you add --rm the container gets deleted if you exit it ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.