Docker Community Forums

Share and learn in the Docker community.

Service 'web' failed to build:


(Aliens9889) #1

Hello everybody, I’m new on docker and I’m working on a project that started before I get in. So my problem is with docker-compose build and docker-compose up -d Cuz I’m trying to run the project for the first time in Windows and I don’t know what I missing around.

When I try to run the docker-compose build this is what I get:

C:\Users\alien\Documents\workspaces\ambit\ambit-pac-gateway>docker-compose build
redis uses an image, skipping
db uses an image, skipping
Building web
Step 1 : FROM python:3.5-alpine
 ---> d1128d077f32
Step 2 : MAINTAINER Sebastián Magrí <sebastian@uakami.com>
 ---> Using cache
 ---> 5ec26ff57103
Step 3 : ARG DJANGO_DEBUG
 ---> Using cache
 ---> 52087671134c
Step 4 : ENV PYTHONUNBUFFERED 1
 ---> Using cache
 ---> e3703f121655
Step 5 : RUN apk update     && apk add          postgresql-dev          ca-certificates          openssl          gcc          libc-dev          libxml2-dev          libxslt-dev          libffi-dev          cairo-dev          pango-dev          jpeg-dev          zlib-dev          gdk-pixbuf          ttf-dejavu     && cp /lib/libz.so /usr/lib     && cp /lib/libz.a /usr/lib     && pip install -U pip setuptools     && rm -rf /var/cache/apk/*
 ---> Using cache
 ---> 4898eb7e684d
Step 6 : ADD . /app
 ---> 4eb59a61f3ac
Removing intermediate container 99967a5deec1
Step 7 : WORKDIR /app
 ---> Running in d331eab4d0e0
 ---> 3cb4b0585d20
Removing intermediate container d331eab4d0e0
Step 8 : RUN sh /app/docker/prepare.sh
 ---> Running in 6f6b65fe0b78
: not found/prepare.sh: line 2:
/app/docker/prepare.sh: set: line 3: illegal option -
ERROR: Service 'web' failed to build: The command '/bin/sh -c sh /app/docker/prepare.sh' returned a non-zero code: 2

this my prepare.sh

> #!/bin/sh

> set -ex

> prepare () {
>     cp pac_gateway/settings/local_docker.py pac_gateway/settings/local.py

>     reqs="`[[ "$DJANGO_DEBUG" = "True" ]] && echo "requirements/development.txt" || echo "requirements/production.txt"`"

>     pip install -U pip setuptools -r $reqs
> }

> prepare

this is my run.sh

#!/bin/sh

cp pac_gateway/settings/local_docker.py pac_gateway/settings/local.py

pip install -U -r `[[ "$DJANGO_DEBUG" = "True" ]] && echo "requirements/development.txt" || echo "requirements/production.txt"`

exec gunicorn --config=/app/gunicorn.py pac_gateway.wsgi

this is Dockerfile

FROM python:3.5-alpine
MAINTAINER Sebastián Magrí <sebastian@uakami.com>

ARG DJANGO_DEBUG

ENV PYTHONUNBUFFERED 1

# Get PostgreSQL 9.5 and base development files for pip builds
# Update pip to its latest release
RUN apk update \
    && apk add \
         postgresql-dev \
         ca-certificates \
         openssl \
         gcc \
         libc-dev \
         libxml2-dev \
         libxslt-dev \
         libffi-dev \
         cairo-dev \
         pango-dev \
         jpeg-dev \
         zlib-dev \
         gdk-pixbuf \
         ttf-dejavu \
    && cp /lib/libz.so /usr/lib \
    && cp /lib/libz.a /usr/lib \
    && pip install -U pip setuptools \
    && rm -rf /var/cache/apk/*

ADD . /app

WORKDIR /app

RUN sh /app/docker/prepare.sh

EXPOSE 8000

CMD sh /app/docker/run.sh

this project is running on Ubuntu, but at work the put me to try on Windows

I don’t know if this relevant for help, but this a Django project

I will appreciate all the help I’ll receive. Thanks you


(David Maze) #2

Are you sure your shell script has Unix line endings? I could imagine extra carriage return characters causing this. If you run something like od -t x1 prepare.sh you should see 0A bytes, but not 0D 0A. If you see the CR/LF pair, you need to convert the file to have Unix line endings (LF only).

You shouldn’t need the cp command at runtime, the identical command is in your prepare script. I’d also run pip install at build time, not startup time. (Do you want to contact the Internet every time you start the container? Will you be happy if today’s change to setuptools broke some intermediate package you depend on and you must fix it before you can run your code?) I’d just replace all of this with

CMD gunicorn --config=/app/gunicorn.py pac_gateway.wsgi


(Aliens9889) #3

Hi dmaze, honestly I’m not sure if I understand what you saying in this part. I’m using the windows normal or standard command prompt. And the part of CR/LF I have not idea about it, if you can explain more about this and if you think this could help me solve my problem I really appreciate it. By the way thanks for your time to helping me with this. It’s my first time with docker and I try to understand it xD


(Aliens9889) #4

I find a Solution. I had to use git bash then you have to find the folder where .sh file is, and type this dos2unix <file.sh> and that’s it.


(Michael Friis) #5

Here’s a good blog post describing how to work with this: https://blogs.msdn.microsoft.com/stevelasker/2016/09/22/running-scripts-in-a-docker-container-from-windows-cr-or-crlf/