3

This question is not duplicated, because I want to obtain an interactive shell without running with -it flags.

I'm moving first steps into Docker to create images only for internal use.

I start from this envirornment_full.df:

FROM ubuntu:16.04
ENTRYPOINT ["/bin/bash"]

I then build

docker rmi environment:full
docker build -t environment:full  -f environment.df .

Then run

docker run environment:full

Running docker images -am I see my image

REPOSITORY          TAG                 IMAGE ID            CREATED         SIZE
environment         full                aa91bbd39167        4 seconds ago   129 MB

So I run it

docker run environment:full 

I see nothing happening ....

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED         STATUS                      PORTS               NAMES
5847c0a18f30        environment:full    "/bin/bash"         21 seconds ago  Exited (0) 20 seconds ago                       admiring_mirzakhani

Also

$ docker run environment:full -ti
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
root@aa768a585f33:/# exit

I'd like to have the ubuntu prompt, like if I was in a SSH connection. And this without user must enter -i or -tty flags.

How can I realize this?

realtebo
  • 23,922
  • 37
  • 112
  • 189
  • Are you sure it's /bin/bash and not /usr/bin/bash? It varies between distros. – Hubert Grzeskowiak Jan 18 '17 at 09:41
  • @nwinkler : added explanation of why it's not a duplicated question – realtebo Jan 18 '17 at 09:48
  • 2
    Is there a reason you don't want the `-it` flags? It seems to me that Docker is just optimized in a way to not allocate a tty and not enable STDIN by default. In most scenarios you'd want this default behaviour. In your case it's not the default, therefore you need the flags. I think this could be a potential feature request for Docker. – Hubert Grzeskowiak Jan 18 '17 at 09:53
  • @HubertGrzeskowiak: i'm moving to docker from VMs "environment", so I've not fully understood the docker main goals. I'll go on studying and coding more and more to grab the docker philosophy – realtebo Jan 19 '17 at 07:14

1 Answers1

7

bash won't run at all if stdin is closed. If you don't provide the -i flag, bash will simply exit immediately. So when you...

docker run environment:full 

...bash exits immediately, and so your container exits. You would see it if you ran docker ps -a, which shows container that have stopped.

bash won't give you an interactive prompt if it's not attached to a tty. So if you were to run...

coerk run -i environment:full

...you would get a bash shell, but with no prompt, or job control, or other features. You need to provide -t for Docker to allocate a tty device.

You can't get what you want without providing both the -i and -t options on the command line.

An alternative would be to set up an image that runs an ssh daemon, and have people ssh into the container. Instead of behaving "like if I was in a SSH connection", it would actually be an ssh session.

Also, note that this:

docker run environment:full -ti

Is not the same as this:

docker run -it environment:full

The former will run bash -ti inside a container, while the latter passes the -i and -t options to docker run.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • 2
    Thanks ! This is a exemplar answer in the case of "is it not possibile". You've explained why and also done it well. – realtebo Jan 19 '17 at 07:13