aschmid00
aschmid00

Reputation: 7158

start redis-server on debian/ubuntu boot

I am trying to create a docker container where redis starts at boot. there will be other foreground services running on that other container which will connect to the redis db.

for some reason the service does not start when i run the container. here my simplified Dockerfile

FROM debian

# this solves an issue described here:
# http://askubuntu.com/questions/365911/why-the-services-do-not-start-at-installation
RUN sed -i -e s/101/0/g /usr/sbin/policy-rc.d

# install redis-server
RUN apt-get update && apt-get install -y redis-server

# updates init script (redundant)
RUN update-rc.d redis-server defaults 

# ping google to keep the container running in foreground
CMD ["ping", "google.com"]

can anybody explain me why this is not working and how this should be done right?

Upvotes: 2

Views: 2105

Answers (2)

Scott Byers
Scott Byers

Reputation: 3205

Digging up an old question here, but I landed on it whilst trying to package a really simple Redis job queue into an existing docker image setup. I needed it to start up on image boot so the app could have access to it. Memory and performance are not a concern in this scenario or an external Redis server would absolutely be the right choice.

Here's what I did in my Dockerfile for a simple NodeJs app to make it work without editing any system files post-install:

RUN apt-get update && apt-get -y redis-server
CMD service redis-server start & node dist/src/main

Sort of crude using parallel command processes, but as the accepted answer points out this is not a real operating system so we really only care about Redis being online when the app is.

Upvotes: 0

Peter Lyons
Peter Lyons

Reputation: 146064

So a docker container is like a full OS but has some key differences. It's not going to run a full init system. It's designed and intended to run a single process tree. While you can run a supervisor such as runit et al within a container, you are really working against the grain of docker and all the tooling and documentation is going to lead you away from using containers like VMs and toward the harmony of 1 process/service per container.

So redis isn't starting because the ping command is literally the only process running in your container.

there will be other foreground services running on that other container which will connect to the redis db.

Don't do it this way. Really. Everything will be easier when you put 1 process in each container and connect them via network links.

Upvotes: 2

Related Questions