Docker: ./entrypoint.sh not found

Viewed 8530

I am trying to setup a django project and dockerize it. I'm having trouble running the container. As far as I know, it's successfully abe to build it, but fails to run.

This is the error I get:

ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"./entrpoint.sh\": stat ./entrpoint.sh: no such file or directory": unknown ERROR: Encountered errors while bringing up the project.

This is the dockerfile:

FROM python:3.6

RUN mkdir /backend
WORKDIR /backend
ADD . /backend/

RUN pip install -r requirements.txt

RUN apt-get update \
    && apt-get install -yyq netcat

RUN chmod 755 entrypoint.sh

ENTRYPOINT ["./entrpoint.sh"]

This is the compose file:

version: '3.7'

services:
  db:
    image: postgres:12.0-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      - POSTGRES_USER=django
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=database

  web:
    restart: on-failure
    build: .
    container_name:backend
    volumes:
      - .:/backend
    env_file:
      - ./api/.env
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
    hostname: web
    depends_on:
      - db

volumes:
  postgres_data:

And there is an entrypoint file which runs automatic migrations, if any: Here is the script:

#!/bin/sh

if [ "$DATABASE" = "postgres" ]
then
    echo "Waiting for postgres..."

    while ! nc -z $SQL_HOST $SQL_PORT; do
      sleep 0.1
    done

    echo "PostgreSQL started"
fi

python manage.py migrate

exec "$@"

Where am I going wrong?

1 Answers

The problem is that you it's not the entrypoint.sh missing but the nc command.

To solve this you have to install the netcat package.

Since python:3.6 is based on debian buster, you can simply add the following command after the FROM directive:

RUN apt-get update \
    && apt-get install -yyq netcat

EDIT for further improvements:

  • copy only the requirements.txt, install the packages then copy the rest. This will improve the cache usage and every build (after the first) will be faster (unless you touch the requirements.txt)
  • replace the ADD with COPY unless you're exploding a tarball

The result should look like this:

FROM python:3.6

RUN apt-get update \
    && apt-get install -yyq netcat

RUN mkdir /backend
WORKDIR /backend
COPY requirements.txt /backend/

RUN pip install -r requirements.txt

COPY . /backend/

ENTRYPOINT ["./entrypoint.sh"]
Related