Reputation: 482
In my Dockerfile I have
FROM microsoft/dotnet:2.1-sdk
COPY devops/scripts/setup.sh .
RUN ls
RUN chmod +x ./setup.sh
RUN ./setup.sh
WORKDIR /app
Step 3 I am using just to show that file is actually present.
When used in docker-compose this works perfectly on Linux, but when runnning docker-compose up
on Windows it results in
> docker-compose up
Building create_template
Step 1/6 : FROM microsoft/dotnet:2.1-sdk
---> 511c1f563ce6
Step 2/6 : COPY devops/scripts/setup.sh .
---> 3d3bb4ab9bc4
Step 3/6 : RUN ls
---> Running in 43ad6e244ed8
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
setup.sh <---
srv
sys
tmp
usr
var
Removing intermediate container 43ad6e244ed8
---> aa32210d6a87
Step 4/6 : RUN chmod +x ./setup.sh
---> Running in 2d6858495355
Removing intermediate container 2d6858495355
---> 5e0388623851
Step 5/6 : RUN ./setup.sh
---> Running in abb3a52fe6ec
/bin/sh: 1: ./setup.sh: not found
ERROR: Service 'create_template' failed to build: The command '/bin/sh -c ./setup.sh' returned a non-zero code: 127
Is there a way to use same dockerimage files and commands on both systems or do I have to have alternate dockerimage and docker-compose for each? Thank you
Upvotes: 2
Views: 3873
Reputation: 31584
I tried your example on windows & reproduce your problem.
The root cause is when you new the file setup.sh
on windows, it's DOS format
. You need to use git-bash or other similar to transfer the file format on host to unix format
in advance before compose or build, something like:
dos2unix setup.sh
Another way is do it in Dockerfile
, and this also compatible when you use linux host, something like next:
RUN apt-get update && apt-get install -y dos2unix && dos2unix setup.sh
RUN ./setup.sh
Upvotes: 3