nickjj / docker-django-example

A production ready example Django app that's using Docker and Docker Compose.
MIT License
1.2k stars 259 forks source link

Service 'worker' failed to build : Build failed #16

Closed terencetwuo closed 2 years ago

terencetwuo commented 2 years ago

Hi, thanks for the great starter example for someone wanting to get his feet wet in Django.

I have followed the initial steps found in #Running this app.

And I'm facing this error:

Building worker [+] Building 6.3s (18/22)
=> [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 38B 0.0s => [internal] load .dockerignore 0.1s => => transferring context: 35B 0.0s => [internal] load metadata for docker.io/library/python:3.10.2-slim-bullseye 5.5s => [internal] load metadata for docker.io/library/node:16.14.0-bullseye-slim 2.3s => [assets 1/7] FROM docker.io/library/node:16.14.0-bullseye-slim@sha256:f00e66f4e3d5f3cf1322049440f9d84c79462cf2157f6d9bac26cec8d31f950e 0.0s => [internal] load build context 0.3s => => transferring context: 3.03kB 0.2s => [app 1/10] FROM docker.io/library/python:3.10.2-slim-bullseye@sha256:6faf002f0bce2ce81bec4a2253edddf0326dad23fe4e95e90d7790eaee653da5 0.0s => CACHED [app 2/10] WORKDIR /app 0.0s => CACHED [app 3/10] RUN apt-get update && apt-get install -y --no-install-recommends build-essential curl libpq-dev && rm -rf /var/lib/apt/lists/ /usr/share/doc /usr/share/man && apt-get clean 0.0s => CACHED [app 4/10] COPY --chown=python:python requirements.txt ./ 0.0s => CACHED [app 5/10] COPY --chown=python:python bin/ ./bin 0.0s => CACHED [assets 2/7] WORKDIR /app/assets 0.0s => CACHED [assets 3/7] RUN apt-get update && apt-get install -y --no-install-recommends build-essential && rm -rf /var/lib/apt/lists/ /usr/share/doc /usr/share/man && apt-get clean && mkdir -p / 0.0s => CACHED [assets 4/7] COPY --chown=node:node assets/package.json assets/yarn ./ 0.0s => CACHED [assets 5/7] RUN yarn install && yarn cache clean 0.0s => CACHED [assets 6/7] COPY --chown=node:node . .. 0.0s => CACHED [assets 7/7] RUN if [ "development" != "development" ]; then ../run yarn:build:js && ../run yarn:build:css; else mkdir -p /app/public; fi 0.0s => ERROR [app 6/10] RUN chmod 0755 bin/ && bin/pip3-install 0.3s [app 6/10] RUN chmod 0755 bin/* && bin/pip3-install:

11 0.310 /usr/bin/env: ‘bash\r’: No such file or directory

executor failed running [/bin/sh -c chmod 0755 bin/* && bin/pip3-install]: exit code: 127 ERROR: Service 'worker' failed to build : Build failed

Highlighting the error part will be

ERROR [app 6/10] RUN chmod 0755 bin/ && bin/pip3-install 0.3s [app 6/10] RUN chmod 0755 bin/ && bin/pip3-install:

11 0.310 /usr/bin/env: ‘bash\r’: No such file or directory

executor failed running [/bin/sh -c chmod 0755 bin/* && bin/pip3-install]: exit code: 127`

terencetwuo commented 2 years ago

I have identified the cause to be line endings, based on answer from Stackoverflow.

The problem can be resolved by changing the Line Ending sequence, via VS Code:

  1. Open bin/pip3-install file
  2. On the bottom right look for CLRF, click and switch to LF
  3. Save file
  4. docker-compose build
nickjj commented 2 years ago

No problem and yep Windows line endings will cause all sorts of issues in shell scripts that run in Linux.