Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Using RUN command in Dockerfile on Windows and Linux

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

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!