1

I built a Dockerfile where build command was successful

sudo docker build --network=host -t nid-robotic-server .

But when I try to run the file with

docker run -it nid-robotic-server

It jut exits.

rafa@ace:/home/automation$ docker run -it robotic-server
8:C 02 Dec 2018 11:39:05.871 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8:C 02 Dec 2018 11:39:05.871 # Redis version=5.0.2, bits=64, commit=00000000, modified=0, pid=8, just started
8:C 02 Dec 2018 11:39:05.871 # Configuration loaded
rafa@ace:/home/automation$

Can anyone help me with this? It would be a great help.

  • What do you want your container to exectue when it is started? I think you're using the `ENTRYPOINT` instruction wrong. [Read here](https://docs.docker.com/engine/reference/builder/#entrypoint). There's no point in specifying two different `ENTRYPOINT` instructions – gasc Dec 02 '18 at 16:03
  • 1
    Your second ENTRYPOINT is running (see @gasc comment about having two, though), but it runs as a daemon (background) so Docker thinks it's exited and stops the container. Remove the daemonize part of `ENTRYPOINT redis-server --daemonize yes` and see if that keeps it running. – Mike B. Dec 02 '18 at 16:18

2 Answers2

1
docker run -it --entrypoint="/bin/sh" nid-robotic-server

or

docker run -it --entrypoint="/bin/bash" nid-robotic-server

should work for you.

It depends how you configure the ENTRYPOINT and CMD in you dockerfile. If you define something else than shell as entrypoint, you won't be able to "simply" run your container interactively, you need to override the entrypoint with --entrypoint first.

If you are planing to run you images as dameon, setting something other than shell for entrypoint is completely fine and even good practice (which is the usual case with docker).

See https://docs.docker.com/engine/reference/builder/#entrypoint for more info.

michalhosna
  • 7,327
  • 3
  • 21
  • 40
0

You don't have any task to be executed when docker is running. You are using entrypoint in the wrong way. tasks like --daemonized will be run in background. Checking your Dockerfile, no task will be executed when docker is started.

at least add this section in the end of your dockerfile:

CMD ["/bin/sh"]

then by running this command you will be dropped in sh shell of docker.

docker run -it --entrypoint="/bin/sh" nid-robotic-server
Reza Torkaman Ahmadi
  • 2,958
  • 2
  • 20
  • 43