1

I have simple Dockerfile

FROM base

RUN <code which installs redis>
RUN npm install redis-adapter

EXPOSE 6379

ENTRYPOINT redis-server --daemonize yes && /app/tasks/redis/entrypoint.sh

And in my entrypoint I'm setting up some configurational keys and set some data to redis via node:

#!/bin/sh

redis-cli hset app:cfg env dev
redis-cli hset app:cfg maxconnections 1024

node /app/tasks/redis/init.js

Image builds succesfully, but when I running it - nothing happens. What's the problem? What should I do to run redis in container and make some configuration after? May be the trouble is in that I'm running redis as daemon?

wmbtrmb
  • 307
  • 1
  • 17
  • Could you write your error message, please? – Alejandro Galera May 22 '18 at 07:31
  • @AlexGalera There is no error message. On `docker run ` I receive messages from my node script that configuration was successfull and it's all. Looks like: $ docker run a7deb97f2cb5 node_redis: Warning: Redis server does not require a password, but a password was supplied. Reply: OK, app-configs setup Reply: OK, app-runtime setup Reply: OK, cfg setup – wmbtrmb May 22 '18 at 07:43
  • Could you post `docker logs ` output, please? – Alejandro Galera May 22 '18 at 07:47
  • Same as text above. Success messages from node script and it's all. – wmbtrmb May 22 '18 at 07:50
  • Does it works if you execute the same steps outside container? – Alejandro Galera May 22 '18 at 07:50
  • Yes, it runs redis-server on default port 6379, after starts my node script which configures keys. But redis-server was running as daemon, so when I execute that outside container I'm also get ok message from script and then can connect to redis via `redis-cli` or something. I'm wondering why container doesn't runs. What should do `CMD` or `ENTRYPOINT`? If it returns `0` does container starts? – wmbtrmb May 22 '18 at 07:54

1 Answers1

1

Answer from author

TL:DR

There is a pretty similiar question in Stackoverflow which help to fix my problem:

The problem was in that a Docker ENTRYPOINT or CMD should "spawn single process". And I put Redis starting and node init.js execution as different programs into supervisord. Providing supervisord.conf for example:

[supervisord]
nodaemon=true
loglevel=debug

[program:redis]
priority=1
command=redis-server

[program:configurations]
priority=2
command=/bin/sh -c /app/tasks/redis/entrypoint.sh

Why did I do that?

The main trouble which I have with this issue was with misunderstanding what actually is a Docker container. And what does ENTRYPOINT or CMD in Docker. I thought that I should just "run some server into Docker and expose some port and Docker will do everything with itself", but that is not the way how containers work. There is a difference between containers and VM's. Look this: How is Docker different from a virtual machine?

When thinking about Docker container as a wrap over one single process it seems clear that code written in my Dockerfile will not work in way that I was expected.

If there is a need to run multiple processes in Docker container then you should use something like supervisord or concurrently (if you prefer Node ecosystem).

wmbtrmb
  • 307
  • 1
  • 17