码头工人:./ entrypoint.sh找不到

我正在尝试设置一个django项目并将其泊坞窗化。 我在运行容器时遇到问题。 据我所知,它已经成功构建,但是无法运行。

This is the error I get: enter image description here

这是dockerfile:

FROM python:3.6

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

RUN pip install -r requirements.txt

ENTRYPOINT ["./entrypoint.sh"]

这是撰写文件:

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:

还有一个运行自动迁移的入口点文件,如果有的话: 这是脚本:

#!/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 "$@"

我要去哪里错了?

评论
  • 路飞
    路飞 回复

    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
    

    编辑以进一步改进:

    • 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

    结果应如下所示:

    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"]