Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

No permission to run docker-entrypoint.sh although it is set in Dockerfile

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading