Docker Community Forums

Share and learn in the Docker community.

Issues with bash script and docker container

docker

(Jhechtf) #1

I’m having the strangest thing with a custom docker image I’m trying to build for my job.

Long and short of it is that it’s going to be used for a ruby on rails app that we’re serving up via puma, using nginx as a reverse proxy. The eventual plan is to have the nginx / rails be separate containers, but for right now I’m just trying to get them working using a single image. The issue is that the image dies immediately upon creation using with the following error:

standard_init_linux.go:190: exec user process caused “exec format error”

I looked around and found a couple of places that seem to indicate that the main error would be that I am creating the start.sh file on windows, which uses CRLF, which can cause errors with the shebang up top. I tried multiple times converting from CRLF to LF in VSCode, but found it didn’t change anything. I did find that when I ran file start.sh that it was saying that it was solely an ASCII file, and not an executable.

To get around all of this I created the file in the linux container itself and used docker cp to extract the file from the container. If I go into the container using docker run -it rails-nginx bash and run file start.sh I get

start.sh: Bourne-Again shell script, ASCII text executable

But even after rebuilding the image the container still immediately dies.

Ideas, anyone?

Dockerfile

FROM ruby
RUN apt-get update -y && apt-get install -y curl nginx && gem install bundler rails && \
    curl -sSL https://deb.nodesource.com/setup_10.x | bash - &&\
    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list &&\
    apt-get update -y && apt-get -y install nodejs yarn
VOLUME /var/www/rails-app
WORKDIR /var/www/rails-app
ADD start.sh /var/www/rails-app
RUN chmod +x start.sh
ADD default.conf /etc/nginx/sites-available/default
CMD ["./start.sh"]

Note: I’ve also tried to change it to the full path, CMD ["/var/www/rails-app/start.sh"] with no change in outputp

start.sh

#!/bin/bash
bundle install
service nginx start
rails server

I’m not going to add default.conf as this doesn’t seem to pertain to it – nginx starts just fine and if I mount the volume and start the rails server manually it works without issue.