Docker Compose can't start container process - docker

I use a windows laptop
This is the error
ERROR: for web Cannot start service web: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "flask": executable file not found in $PATH: unknown
ERROR: Encountered errors while bringing up the project.
Below is the dockerfile
#syntax=docker/dockerfile:1
FROM python:3.7-alpine
WORKDIR /code .
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN python -m pip install -r requirements.txt
EXPOSE 5001
COPY . .
CMD ["python", "-m", "Flask", "run"]
Everything concerning the code is here https://docs.docker.com/compose/gettingstarted/

Related

Giving execution right to entrypoint script does not working in Dockerfile

I have the following Dockerfile:
# pull official base image
FROM python:3.9.7-alpine
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev binutils \
&& apk add --no-cache proj-dev geos gdal
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# copy entrypoint.sh
COPY ./entrypoint.sh .
RUN sed -i 's/\r$//g' /usr/src/app/entrypoint.sh
RUN chmod +x /usr/src/app/entrypoint.sh
# copy project
COPY . .
# run entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
Building the image works fine, but when I try a docker run after building the image I get the following error:
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/usr/src/app/entrypoint.sh": permission denied: unknown.
ERRO[0000] error waiting for container: context canceled
The line RUN chmod +x /usr/src/app/entrypoint.sh doesn't seem to work because when I comment the ENTRYPOINT statement, build the image then start a containerI can see that the execution right isn't added for that file.
Docker version is:
Docker version 20.10.23, build 7155243
I tried replacing the RUN chmod line with a --chmod=777 option to the COPY of the entrypoint and it didn't change anything.
Any idea why a chmod +x would fail in docker ?
I found a workaround by removing the chmod line and replacing the entrypoint line with the following:
ENTRYPOINT ["/bin/sh", "/usr/src/app/entrypoint.sh"]
This way there is no need for a execution right on the entrypoint script.
But I still don't know why the chmod doesn't work.

dockerfile pip install -r requirements.txt giving file not found error

Here's my dockerfile:
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
COPY ./app /app/app
WORKDIR /app/app
RUN "pip install -r requirements.txt"
And here's my folder structure:
When I try to build the image using docker build -t myimage ., I get the following error:
Any insight into resolving this would be appreciated.
Try
RUN ["pip", "install", "-r", "requirements.txt"]

Why does Docker report the entrypoint file doesn't exist when ls reports it does exist?

I'm using Docker v 19. I have this at the end of my web/Dockerfile ...
FROM python:3.7-slim
RUN apt-get update && apt-get install
RUN apt-get install -y dos2unix
RUN apt-get install -y libmariadb-dev-compat libmariadb-dev
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc \
&& rm -rf /var/lib/apt/lists/*
RUN python -m pip install --upgrade pip
WORKDIR /app/
COPY requirements.txt requirements.txt
COPY entrypoint.sh entrypoint.sh
RUN tr -d '\r' < entrypoint.sh > /app/entrypoint2.sh
RUN ls /app/entrypoint2.sh
RUN ls /app/
RUN python -m pip install -r requirements.txt
RUN ls /app/entrypoint.sh
RUN dos2unix /app/entrypoint.sh
RUN ls /app/entrypoint.sh
RUN chmod +x /app/*.sh
RUN ls ./
ENTRYPOINT ["./entrypoint2.sh"]
However, when I run "docker-compose up" (which references the above), the "entrypoiet" file can't be found, which is baffling because the line above ("ls ./") shows that it exists ...
Step 14/19 : RUN ls /app/entrypoint.sh
---> Running in db8c11ce3fad
/app/entrypoint.sh
Removing intermediate container db8c11ce3fad
---> c23e69de2a86
Step 15/19 : RUN dos2unix /app/entrypoint.sh
---> Running in 9e5bbd1c0b9a
dos2unix: converting file /app/entrypoint.sh to Unix format...
Removing intermediate container 9e5bbd1c0b9a
---> 32a069690845
Step 16/19 : RUN ls /app/entrypoint.sh
---> Running in 8a53e70f219b
/app/entrypoint.sh
Removing intermediate container 8a53e70f219b
---> 5444676f45fb
Step 17/19 : RUN chmod +x /app/*.sh
---> Running in 5a6b295217c8
Removing intermediate container 5a6b295217c8
---> 8b5bfa4fd75a
Step 18/19 : RUN ls ./
---> Running in 9df3acb7deb7
entrypoint.sh
entrypoint2.sh
requirements.txt
Removing intermediate container 9df3acb7deb7
---> 009f8bbe18c8
Step 19/19 : ENTRYPOINT ["./entrypoint2.sh"]
---> Running in 41a7e28641a7
Removing intermediate container 41a7e28641a7
---> 34a7d4fceb8b
Successfully built 34a7d4fceb8b
Successfully tagged maps_web:latest
WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
...
Creating maps_web_1 ... error
ERROR: for maps_web_1 Cannot start service web: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"./entrypoint2.sh\": stat ./entrypoint2.sh: no such file or directory": unknown
How do I tell Docker how to reference that entrypoint file? The docker-compose.yml file section including the above is below
web:
restart: always
build: ./web
ports: # to access the container from outside
- "8000:8000"
env_file: .env
environment:
DEBUG: 'true'
command: /usr/local/bin/gunicorn directory.wsgi:application --reload -w 2 -b :8000
volumes:
- ./web/:/app
depends_on:
- mysql
Based on the provided Dockerfile and docker-compose file you are doing the following
Copy files (entrypoint + requirments) to /app
Install the needed packages
Start containers with the volume that overwrite the content of the /app, which is causing the issue.
To solve the issue you have to do one of the following
Copy all the data from ./web to the docker image and remove the volume
Dockerfile : add the following lines
WORKDIR /app/
COPY ./web /app
Docker-compose: remove the below lines
volumes:
- ./web/:/app
The second option is to change the path of the entry point so it does not conflict with the volume
Dockerfile
RUN tr -d '\r' < entrypoint.sh > /entrypoint2.sh
RUN chmod +x /entrypoint2.sh
ENTRYPOINT ["./entrypoint2.sh"]

tesseract-ocr not recognized by alpine docker container

I am trying to install tesseract-ocr to use within a docker container, but when I feed a request to my api, I still get an error saying "FileNotFoundError: [Errno 2] No such file or directory: 'tesseract': 'tesseract'"
I'm trying to maybe add tesseract to my ENV $Path variable in the Dockerfile, but I'm unable to locate where this tesseract package is even installed. Below I've added my Dockerfile, any help would be appreciated. Thanks!
FROM python:3.6-alpine
RUN apk add --update --no-cache tesseract-ocr
FROM pytorch/pytorch:1.4-cuda10.1-cudnn7-devel
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN pip install .
EXPOSE 5000
WORKDIR /usr/src/app/examples/classification
CMD ["flask", "run", "--host", "0.0.0.0"]

starting container process caused "exec: \"/app\": permission denied": unknown

When I was trying to build golang using docker
The image build of docker was successful, but the following error occurred when running with docker run
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/app\": permission denied": unknown.
I think this error cause no user add, so I added group and user as below
RUN groupadd -g 10001 myapp \
&& useradd -u 10001 -g myapp myapp
but didn't fix.
Here is my source docker file
FROM golang:1.12.9 as builder
ADD . /go/src/appname/
WORKDIR /go/src/appname/
ENV GO111MODULE=on
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make build target=prod
FROM alpine
RUN apk update \
&& apk add --no-cache
COPY --from=builder /go/src/ /app
ENTRYPOINT [ "/app" ]
thanks
You are copying your entire source folder into the directory /app in this step:
COPY --from=builder /go/src/ /app
Then you try to execute the directory:
ENTRYPOINT [ "/app" ]
Instead, you need to copy the compiled binary that your go build outputs in the copy step.
You need to specify the output directory to your binary.
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /app .
then copy the app directory
COPY --from=builder /app ./
RUN chmod +x ./app
ENTRYPOINT ["./app"]
Thanks to the advice of everyone, I fix this issue
I couldn't just COPY with the build binary properly specified
before
COPY --from=builder /go/src/ /app
after
COPY --from=builder /go/src/build/build_app_name /app
thanks!!

Resources