1

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?

St.Antario
  • 26,175
  • 41
  • 130
  • 318
  • @LinPy `-t` flag has no effect on the `start` command. `unknown shorthand flag: 't' in -t See 'docker container start --help'.` `-i` can be specified though. – St.Antario Nov 22 '19 at 08:29
  • 1
    Sorry I did not notice that start. I think there is no way to prevent it to stop – LinPy Nov 22 '19 at 08:33
  • @LinPy But what I am actually concerned about is if it is possible to use `start -i` for containers that were created without `-i`. Maybe some workarounds? – St.Antario Nov 22 '19 at 08:34
  • yes only if the image has an Entrypoint see my answer here : https://stackoverflow.com/questions/58500866/how-to-restart-an-existing-mongodb-docker-container-with-a-new-flags-to-daemon/58501700#58501700 – LinPy Nov 22 '19 at 08:39
  • Do docker exec -it 57806f93e42c bash – Varun Mukundhan Nov 22 '19 at 09:03

1 Answers1

1

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

Adiii
  • 54,482
  • 7
  • 145
  • 148