Reputation: 2492
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.
Upvotes: 0
Views: 1008
Reputation: 7935
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.
Upvotes: 0
Reputation: 35109
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.
Upvotes: 1