nickjj / docker-flask-example

A production ready example Flask app that's using Docker and Docker Compose.
MIT License
618 stars 102 forks source link

Getting Error with docker compose => ERROR [helloflask_web app 6/9] RUN chmod 0755 bin/* && bin/pip3-install #4

Closed AndruMace closed 3 years ago

AndruMace commented 3 years ago

My steps:

  1. git clone https://github.com/nickjj/docker-flask-example backend
  2. cd backend
  3. cp .env.example .env
  4. cp docker-compose.override.yml.example docker-compose.override.yml
  5. docker-compose up --build
  6. ERROR (see below for full log)

[+] Building 13.7s (20/44) => [helloflask_web internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 32B 0.0s => [helloflask_webpack internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 32B 0.0s => [helloflask_worker internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 32B 0.0s => [helloflask_web internal] load .dockerignore 0.0s => => transferring context: 35B 0.0s => [helloflask_worker internal] load .dockerignore 0.1s => => transferring context: 35B 0.0s => [helloflask_webpack internal] load .dockerignore 0.5s => => transferring context: 35B 0.0s => [helloflask_web internal] load metadata for docker.io/library/python:3.9 11.4s => [helloflask_webpack internal] load metadata for docker.io/library/node:1 11.0s => [helloflask_webpack internal] load build context 0.6s => => transferring context: 1.71kB 0.1s => [helloflask_worker webpack 1/8] FROM docker.io/library/node:14.17.5-bulls 0.0s => CACHED [helloflask_worker webpack 2/8] WORKDIR /app/assets 0.0s => CANCELED [helloflask_webpack webpack 3/8] RUN apt-get update && apt-get 1.9s => [helloflask_web internal] load build context 0.6s => => transferring context: 3.16kB 0.1s => [helloflask_worker internal] load build context 0.6s => => transferring context: 194.00kB 0.1s => [helloflask_web app 1/9] FROM docker.io/library/python:3.9.6-slim-bullsey 0.0s => CACHED [helloflask_web app 2/9] WORKDIR /app 0.0s => CACHED [helloflask_web app 3/9] RUN apt-get update && apt-get install - 0.0s => CACHED [helloflask_web app 4/9] COPY --chown=python:python requirements. 0.0s => CACHED [helloflask_web app 5/9] COPY --chown=python:python bin/ ./bin 0.0s => ERROR [helloflask_web app 6/9] RUN chmod 0755 bin/ && bin/pip3-install 1.1s

[helloflask_web app 6/9] RUN chmod 0755 bin/* && bin/pip3-install:

24 1.099 /bin/sh: 1: bin/pip3-install: not found


failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c chmod 0755 bin/* && bin/pip3-install]: exit code: 127

Any idea how to resolve this?

nickjj commented 3 years ago

Does bin/pip3-install exist in your cloned directory?

It exists in that spot in the repo: https://github.com/nickjj/docker-flask-example/blob/main/bin/pip3-install

Also did you change anything in the Dockerfile?

AndruMace commented 3 years ago

Wow thanks for responding so quickly!

pip3-install does exist in the correct location bin/pip3-install and no I've made no changes to the Dockerfile.

Edit: I'm on Windows 10 if that additional information helps.

nickjj commented 3 years ago

Are you using WSL 2 or PowerShell?

AndruMace commented 3 years ago

I've tried it both with Powershell and Git-Bash (link below). I'm getting the same error in both.

https://git-scm.com/downloads

nickjj commented 3 years ago

Would it be possible to try WSL / WSL 2?

AndruMace commented 3 years ago

Apologies for the delay, I had to get WSL2 set up on my machine and integrated with docker. Looks like WSL2 via Ubuntu 20.04 LTS did the trick! Strange that neither powershell nor gitbash (which has always served me well in the past) didn't work though. Any ideas how I could get it working with either of those?

nickjj commented 3 years ago

Technically it should work with PowerShell. I'll look into it.

AndruMace commented 3 years ago

Thanks! Best of luck.

nickjj commented 3 years ago

I was able to get it to build with PowerShell here without making any changes.

I did very similar steps as you. Instead of cloning it from github I copied the files from my WSL 2 instance to C:\Users\Nick\docker-flask-example then ran a docker-compose build which worked.

If I were to guess there's some permission issue with the shell scripts in the bin/ directory.

However when I ran it, it fails with permission errors due to Windows not knowing how to deal with Linux file permissions. My Dockerfile is configured to run as a non-root user, but Windows doesn't know how to match the user id / group id of a Linux machine to make the volumes work. This is a limitation of Docker and Windows unfortunately.

I would stick with WSL 2 if you can. It will be a lot faster in the end in terms of file performance if you keep the files inside of WSL 2's file system. Sorry for the bad news but there's no way to reasonably support PowerShell as far as I know. You're more than welcome to dive into the gory details on how Docker handles cross-OS file permissions, but that's a battle I don't want to fight. If you can get it working a PR would be much appreciated and I'd happily merge it in.

AndruMace commented 3 years ago

Gotcha, thanks for the information. I appreciate your time. I'll probably be sticking with WSL2 for the foreseeable future now that I have it installed, honestly I had been putting it off for far too long anyway haha. Have a nice day, thanks again.

nickjj commented 3 years ago

No problem.

Here's a couple of blog posts / videos that may help with keeping your WSL 2 disk space in check btw. There's still some sharp edges around WSL 2 and how it frees up resources: