I created a Docker image and container via docker-compose that consists of a Rails app backed by PostgreSQL. Rails is meant to start via a docker-entrypoint.sh file which looks like this:
#!/bin/sh # Exit early if there are any errors. set -e # Check that there won't be any server conflicts. if [ -f tmp/pids/server.pid ]; then rm tmp/pids/server.pid fi # -b binds the server to all IP addresses, rather than to localhost. bundle exec rails s -b 0.0.0.0 However, the container stops immediately after startup with this error:
bundler: failed to load command: rails (/usr/local/bundle/bin/rails) LoadError: cannot load such file -- /usr/local/bundle/specifications/exe/rails /usr/local/bundle/bin/rails:23:in `load' /usr/local/bundle/bin/rails:23:in `<top (required)>' Since to my knowledge you can't directly explore the filesystem of a stopped container, I exported the entire filesystem to a .tar file:
docker export a2410e604db9 > container.tar Looking inside of container.tar, I found that there is a /usr/local/bundle/bin/rails executable file, so I don't know why bundle wouldn't be able to load that command.
The other directory that is mentioned in the error, /usr/local/bundle/specifications/exe/rails, does not exist. There is only /usr/local/bundle/specifications, which contains a bunch of .gemspec files for the Rails project and nothing else.
What is causing this bundler/LoadError problem?
CMD, not itsENTRYPOINT) you candocker run --rm -it your-image bashto get an interactive shell on the image to poke around.ENTRYPOINT, though, in my Dockerfile:ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"].CMDthen you can override it at run time as shown above. You can also split theENTRYPOINTandCMD; if you make the last line of the scriptexec bundle exec "$@"then whatever command you pass (default:CMD rails s -b 0.0.0.0) will get run in the Bundler context.ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"]andCMD rails s -b 0.0.0.0. I changed the last line of my entrypoint script toexec bundle exec "$@". The container still crashed immediately after start. I then randocker run --rm -it 64e8e33e8fc1 bash, and the Rails server started right there in the console -- no interactive shell, which I thought was the goal -- but the Rails server is inaccessible in the browser, as though it wasn't running. I'm completely lost.ENTRYPOINTtoCMD, and nothing else. I could then rundocker run --rm -it 93350aeeab9c shto get a shell into the image that failed to start. So that's something.