How to run a docker container as a daemon starting the rails project built inside?
I’ve built an image with this Dockerfile:
FROM rails RUN apt-get update RUN mkdir /home/projects WORKDIR /home/projects RUN rails new hello EXPOSE 3000
And this command:
sudo docker build -t="hello" .
Now my question is how to get the container running as a daemon and with the
rails server command ?
One Solution collect form web for “How to run a docker container as a daemon starting the rails project built inside?”
To use a default command with a Dockerfile, you can use CMD:
CMD /bin/rails server
This will run
bash -c /bin/rails server. You can also do
CMD ["/bin/rails", "server"] which avoids the bash parent process.
(I’m not familiar with rails, but you get the idea.)
You can also use
ENTRYPOINT instead of
CMD which has various differences from CMD, such as how you can pass arguments to the main command.
docker run -d hello will run the container as a daemon.