Trying to build a docker container, start.sh not f

2019-05-07 09:56发布

问题:

I'm trying to build a docker container, but it doesn't seem to find my start.sh. It copies it to the container, but it somehow doesnt work.

This is my dockerfile:

FROM ubuntu:16.04

# Install Meteor
RUN apt-get update
RUN apt-get install -y curl
RUN curl https://install.meteor.com/ | sh
RUN meteor npm install --save highcharts

# Entypointscript
COPY start.sh /
RUN chmod u+x /start.sh

# Copy App
COPY /app /app

# UI Expose
EXPOSE 80

ENTRYPOINT /start.sh

And this is my start.sh:

#!/bin/bash

sleep 20
/app/meteor run 

# don't exit 
/usr/bin/tail -f /dev/null

Also I'm not sure about that meteor run command in the start.sh. How do I tell meteor run to be executed in a specific directory, without being able to cd into it?

I'm using Windows 10. I have my meteor app in the \app\ directory and the Dockerfile and start.sh in the same directory as the app folder.

I build the container using: docker build -t meteorapp .

The error when I'm trying to run using:

docker run -p 80:80 --net docker-network --name meteorapp meteorapp

is:

/bin/sh: 1: /start.sh: not found

Thank you very much!

回答1:

I'm also running on Windows 10 and the fix for me was to change line endings from CR LF (windows) to LF (Unix).

I did this with Notepad++ making this very easy and now I can build images. In "Edit" menu of Notepad++, you have "EOL conversion" that does exactly what you need.



回答2:

Try adding WORKDIR to the location where start.sh is added.Like so :

WORKDIR /
ENTRYPOINT /start.sh

Since this did not work , you can try out the following two things :

1.Since you are working on windows ,make sure the EOL Conversion for the start.sh is of UNIX format.

2.Secondly , update your entry point to the following :

ENTRYPOINT ./start.sh


回答3:

Turns out there wasn't anything wrong with my files. I created a new directory on my pc, created new files and copied the contents of the start.sh and Dockerfile and my app there. The error was gone. This has to be some serious bug, my friend just got the same error with other files that work on my pc as well.

Maybe some issue with Docker and Windows 10.

EDIT: couldn't fix it for my friend and I run into the same issue again. Someone an idea how to fix?

SOLUTION: It is a incompatibility of the start.sh which is created under windows and with the one linux needs. To solve this, add this to the dockerfile, after you copied the start.sh:

RUN dos2unix /start.sh

If dos2unix is not installed, you have to install it first:

RUN apt-get install dos2unix