St.Antario
St.Antario

Reputation: 27385

Interactive mode is ignored for containers ran without it

I'm trying to understand the way docker container start works and use the following Dockerfile:

FROM ubuntu:18.04

WORKDIR /root

RUN apt-get update && apt-get install -y \
                      curl \
                      gnupg2 \
                      git

CMD ["/bin/bash"]

Now I build an image as

docker image build -t tst .

and run the container as follows:

docker container run -d tst

I run it without interactive mode so it exited as soon as the command execution completes. Now I tried to start this container in an interactive mode:

docker container start -i 57806f93e42c

But it immediately exits as it would run non-interactively:

STATUS                                                                                                   
Exited (0) 9 seconds ago

Is there a way to override "interactiveness" for an already created container?

Upvotes: 1

Views: 1015

Answers (1)

Adiii
Adiii

Reputation: 59956

This is because you container run in detach mode without allocating pseudo-TTY, as bash is the main process of your container so it will exit immediately.

That means, when run in background (-d), the shell exits immediately.

Docker container will automatically stop after "docker run -d"

All you need to allocate pseudo-tty

docker container run -dit tst

and the next command

docker container start -i 57806f93e42c

you just trying to start the stoped container, but again it will exit immediately, it does not create new container but trying to start stopped container.

docker container stop

Start one or more stopped containers

container_start

Upvotes: 1

Related Questions