简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM