2

Tried a lot already, but doesn't want to run docker-compose with entrypoint... I'm new to docker and trying to figure it out, but I can't seem to run the program through entrypoint.sh


Dockerfile

FROM python:3.7-alpine
WORKDIR /app

RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev

ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0

RUN /usr/local/bin/python3 -m pip install --upgrade pip

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY /web .

COPY entrypoint.sh entrypoint.sh
RUN chmod u+x ./entrypoint.sh

docker-compose.yml

version: "3.9"

services:
  web:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - ./web:/app
    environment:
      PG_HOST: pg
      PG_USER: ${POSTGRES_USER}
      PG_PASSWORD: ${POSTGRES_PASSWORD}
      PG_DB: ${POSTGRES_DB}
    depends_on:
      - pg
    entrypoint: entrypoint.sh

  pg:
    image: "postgres:alpine"
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    #      PGDATA: /var/lib/postgresql/data/pgdata
    #    volumes:
    #      - ./data/pgdata:/var/lib/postgresql/data/pgdata
    ports:
      - 5432:5432

entrypoint.sh

#python3 manage.py db upgrade
flask run --host=0.0.0.0

enter image description here

ERROR:

Step 1/11 : FROM python:3.7-alpine
 ---> c051b8594107
Step 2/11 : WORKDIR /app
 ---> Using cache
 ---> d19c508ff35c
Step 3/11 : RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
 ---> Using cache
 ---> 19b5e197621a
Step 4/11 : ENV FLASK_APP=app.py
 ---> Using cache
 ---> af02528555c4
Step 5/11 : ENV FLASK_RUN_HOST=0.0.0.0
 ---> Using cache
 ---> 4029b777d985
Step 6/11 : RUN /usr/local/bin/python3 -m pip install --upgrade pip
 ---> Using cache
 ---> e94f1f70106b
Step 7/11 : COPY requirements.txt requirements.txt
 ---> Using cache
 ---> fb4ad7239fa2
Step 8/11 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> 1f912edd8219
Step 9/11 : COPY /web .
 ---> Using cache
 ---> 32966afa52ee
Step 10/11 : COPY entrypoint.sh entrypoint.sh
 ---> Using cache
 ---> 11525954905f
Step 11/11 : RUN chmod u+x ./entrypoint.sh
 ---> Using cache
 ---> 575c41093e1f
...
Successfully built 89b11d4d5f71
Successfully tagged rodauth_web:latest
rodauth_pg_1 is up-to-date
Recreating 1e4f3f2f6898_rodauth_web_1 ... 
Recreating 1e4f3f2f6898_rodauth_web_1 ... error
ERROR: for 1e4f3f2f6898_rodauth_web_1  Cannot start service web: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "entrypoint.sh": executable file not found in $PATH: unknown

ERROR: for web  Cannot start service web: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "entrypoint.sh": executable file not found in $PATH: unknown
Encountered errors while bringing up the project.

tried adding command RUN chmod u+x ./entrypoint.sh but the problem is not gone.

Added the build log for COPY entrypoint.sh entrypoint.sh part.

gohxr
  • 101
  • 3
  • 10

4 Answers4

3

Your entrypoint.sh file get removed from the container when you mount ./web to /app folder as a volume in docker-compose file. so copy entrypoint to root

COPY entrypoint.sh /entrypoint.sh
RUN chmod u+x /entrypoint.sh

And set entrypoint in docker-compose as

entrypoint: /entrypoint.sh
Ravisha Hesh
  • 1,504
  • 13
  • 19
  • Getting new error: ```4ace05b8cde8_rodauth_web_1 | standard_init_linux.go:219: exec user process caused: exec format error``` – gohxr Jan 31 '21 at 19:18
  • https://stackoverflow.com/a/54901882/3018183 you need to tell executor that your entrypoint.sh file needs to be run as a shell or bash script(more info https://en.wikipedia.org/wiki/Shebang_%28Unix%29) – Ravisha Hesh Jan 31 '21 at 19:23
  • Thanks, u have put an end to my hustle with this issue – Odwori Feb 16 '22 at 07:45
1

First, if you want the script to be the normal entrypoint for the image, I'd move that into the Dockerfile with the following:

ENTRYPOINT ["./entrypoint.sh"]

As for why you'd see a file not found error on a script, several potential reasons:

  1. The first line, e.g. #!/bin/bash, points to a command that does not exist in the image you are using. You need to update your script to use the right shell, or change base images to one that includes your shell.

  2. The script is formatted with Windows linefeeds that include a CR before the LF. That turns /bin/sh into /bin/sh^M (sometimes shown as /bin/sh\r) which doesn't exist in the filesystem. This can be fixed by changing the line feed format in your editor, fixing Git to change how linefeeds are automatically changed, or using a tool like dos2unix.

  3. If you run an image for a different platform, and have qemu binfmt_misc installed but without the --fix-binary option, it will look for the interpreter for your platform inside the image rather that from the host. Often this can be fixed with a newer version of binfmt_misc.

The exec format error mentioned in the comments indicates you are running an image designed for another platform on your host. Docker will attempt to pull the proper platform if you have a multi-platform image. However if the image is only built for one platform, and you try to run it on a different platform without something like qemu's binfmt_misc properly configured, you'll get errors. And the fix for that is to change base images to one that supports that CPU architecture and binary format where you are running the image.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • Ran into this issue on an alpine linux image which apparently doesn't come with bash, but my shebang was `#!/bin/bash`. Changing it to `#!/bin/sh` fixed the issue. – fooiey May 24 '23 at 16:53
0

instead of COPY /web ., just do COPY . /app where you are copying the same structure into /app. as you mentioned, workdir /app you are already in that app folder.

or you can just change the last line, COPY entrypoint.sh .

simple docker example : https://github.com/cerofrais/baiscs/tree/master/basic_docker

cerofrais
  • 1,117
  • 1
  • 12
  • 32
  • I tried both ways, but the error remains identical – gohxr Jan 31 '21 at 18:13
  • now the error has changed from not being able to find to some issue in the file. when you do `COPY entrypoint.sh entrypoint.sh ` it does it in root path, when you run do sh ./entrypoint.sh it runs from root path which doesnt know anything about app. so you have to do `COPY entrypoint.sh .` in step number 10 and run `RUN chmod u+x ./app/entrypoint.sh` – cerofrais Feb 01 '21 at 06:46
0

This is how I customized Ravisha Hesh's answer and it worked for me.

COPY entrypoint.sh /entrypoint.sh
RUN chmod u+x /entrypoint.sh
CMD ["/entrypoint.sh"]
Odwori
  • 1,460
  • 13
  • 14