5

Please help. When I want to go into a container is says

Error response from daemon: Container 90599013c666d332ff6560ccde5053d9127e72042ecc3887550aef90fa1d1eac is not running

My DockerFile:

FROM ubuntu:16.04

MAINTAINER Anton Lapitski <a.lapitski@godeltech.com>

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app


ADD ./ /usr/src/app

EXPOSE 80

ENTRYPOINT ["/bin/sh", "-c", "/usr/src/app/entry.sh"]

Starting script - start.sh:

sudo docker build -t starter .
sudo docker run -t -v mounted-directory:/usr/src/app/mounted-directory -p 80:80 starter

entry.sh script:

echo "Hello World"
ls -l
pwd
if mountpoint -q /mounted-directory 
then
  echo "mounted"
else
  echo "not mounted"
fi

sudo docker ps -a gives:

CONTAINER ID   IMAGE  COMMAND CREATED STATUS   PORTS   NAMES
90599013c666   starter "/bin/sh -c /usr/src…"   18 minutes ago      Exited (0) 18 minutes ago                       thirsty_wiles

And mosе important:

sudo docker exec -it 90599013c666 bash
Error response from daemon: Container 90599013c666d332ff6560ccde5053d9127e72042ecc3887550aef90fa1d1eac is not running

Please could you tell what I am doing wrong? P.S adding -d flag when running not helped.

Antony Lapitskiy
  • 51
  • 1
  • 1
  • 7

4 Answers4

8

Once the ENTRYPOINT completes (in any form), the container exits.

Once the container exits, you can't docker exec into it.

If you want to get a shell on the image you just built to poke around in it, you can

sudo docker run --rm -it --entrypoint /bin/sh starter

To make this slightly easier to run, you might change ENTRYPOINT to CMD in your Dockerfile. (Docker will run the ENTRYPOINT passing the CMD as command-line arguments; or if there is no entrypoint just run the CMD.)

...
RUN chmod +x ./app.sh
CMD ["./app.sh"]

Having done that, you can more easily override the command

sudo docker run --rm -it starter /bin/sh
David Maze
  • 130,717
  • 29
  • 175
  • 215
2

You can try docker start container_id and then docker exec -ti container_id bash for a stopped container.

JasonWayne
  • 1,724
  • 1
  • 19
  • 16
0

You cannot execute the container, because your ENTRYPOINT script has been finished, and the container stopped. Try this:

  1. Remove the ENTRYPOINT from your Dockerfile
  2. Rebuild the image
  3. run it with sudo docker run -it -v mounted-directory:/usr/src/app/mounted-directory -p 80:80 starter sh

The key is the i flag and the sh at the end of the command.

lependu
  • 1,160
  • 8
  • 18
  • I need ENTRYPOINT because it runs entry.sh script. And even if I do as you said trying again to run exec -it command on container reproduces the error:( – Antony Lapitskiy Nov 17 '18 at 08:29
  • Your entry script is executed, but stops the container, since it stops cleanly. You do need to start a process, which runs forever. Like described in https://stackoverflow.com/questions/43419500/how-do-you-start-a-docker-ubuntu-container-into-bash – triplem Nov 17 '18 at 08:54
  • To run forever I just to nee to add -d flag when running container. But that does not help. – Antony Lapitskiy Nov 17 '18 at 09:14
  • @AntonyLapitskiy with -d flag it runs as daemon (in the background) but it still stop when script ends, which is his main problem here as I mentioned in my first sentece in the answer. If you need the `ENTRYPOINT` script, than you need such a script which does not exists. Eg a phyton http server. – lependu Nov 17 '18 at 09:30
  • So could you write to me some working case if you know how to do it please. And one moment is about that when i deleting ENTRYPOINT from docker file i can go to a container without any problem. – Antony Lapitskiy Nov 17 '18 at 09:33
  • I am afraid that is an entirely new problem and question. Please, see [how to write good question](https://stackoverflow.com/help/how-to-ask) – lependu Nov 17 '18 at 09:36
0

I tried these two commands and it works:

sudo docker start <container_id>
docker exec -it <containerName> /bin/bash
m4n0
  • 29,823
  • 27
  • 76
  • 89