0

I am new to docker and I created a docker image which runs a rails app. Now I want to run the app in background as a deamon, but it keeps on bailing out on me:

docker run -d -p 2000:2000 image_name "source ~/.bash_profile; cd src; rails s"

As you can see, my rails app is in the src directory.

I have also tried adding the rails path in the bashrc for the docker image, still it errors out as below:

Can somebody please correct me.

2

2 Answers 2

1

You can wrap your commands in something like startup.sh, then make it executable. Then simply call docker run -d -p 2000:2000 image_name startup.sh or if you want to always run this command when the container is started, take a look at CMD and ENTRYPOINT commands.

Also keep in mind that to keep docker containers running, you need to keep a process active in the foreground.

Sign up to request clarification or add additional context in comments.

Comments

0

Try the following approach:

docker run -d -p 2000:2000 image_name sh -c 'source ~/.bash_profile; cd src; rails s'

This is because docker doesn't support running multiple commands, while "sh -c " is one command.

Reference: http://timmurphy.org/2015/02/27/running-multiple-programs-in-a-docker-container-from-the-command-line/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.