Even though I'm setting the proper permissions in a Dockerfile, docker-compose up
throws an error:
Attaching to lab-track-raport-app-db-1, lab-track-raport-app-web-1
Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "./docker-entrypoint.sh": permission denied: unknown
My Dockerfile:
# syntax=docker/dockerfile:1
FROM python:3.9
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Set workdir
WORKDIR /code
# Copy project files
COPY . /code/
# Install dependencies
# RUN pip install -r requirements.txt
# Add permissions for the entrypoint file
RUN chmod x "./docker-entrypoint.sh"
# debug
RUN ls -la .
# maybe it's overwritten when mounting volume? set permissions again
CMD ["chmod", " x", "./docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]
docker-compose.yml:
version: "3.9"
services:
db:
image: mysql/mysql-server:latest
environment:
- MYSQL_DATABASE=mariadb
- MYSQL_USER=mariadb
- MYSQL_PASSWORD=mariadb
- MYSQL_PORT=3306
ports:
- 3306:3306
expose:
- 3306
web:
build: .
volumes:
- .:/code
ports:
- "8000:8000"
environment:
- MYSQL_DATABASE=mariadb
- MYSQL_USER=mariadb
- MYSQL_PASSWORD=mariadb
- MYSQL_PORT=3306
depends_on:
- db
docker-entrypoint.sh
#!/bin/bash
echo "Waiting"
./wait-for-it.sh "db:3306"
echo "Apply database migrations"
python manage.py migrate
echo "Seed database"
python manage.py loaddata seed.json
echo "Running the app"
python manage.py runserver 0.0.0.0:8000
CodePudding user response:
You copy your code into the /code
directory, but then at runtime you also map your current directory onto /code
which then 'hides' the /code directory in the image and replaces it with the current directory from your host machine.
Remove the volume mapping, so the container can use the /code
directory in the image
web:
build: .
ports:
- "8000:8000"
environment:
- MYSQL_DATABASE=mariadb
- MYSQL_USER=mariadb
- MYSQL_PASSWORD=mariadb
- MYSQL_PORT=3306
depends_on:
- db