找不到Docker Debian nc命令

时间:2020-01-14 02:29:41

标签: docker docker-entrypoint

当我使用命令Debian从docker-compose构建$ docker-compose -f docker-compose-dev.yml build web映像时,如下所示:

docker-compose-fev.yml

services:

  web:
    build:
      context: ./services/web
      dockerfile: Dockerfile-dev
    volumes:
      - './services/web:/usr/src/app'  
    ports:
      - 5001:5000
    environment:
      - FLASK_ENV=development
      - APP_SETTINGS=project.config.DevelopmentConfig
      - DATABASE_URL=postgres://postgres:postgres@web-db:5432/web_dev 
      - DATABASE_TEST_URL=postgres://postgres:postgres@web-db:5432/web_test
      - SECRET_KEY=my_precious
    depends_on:  
      - web-db
      - redis

似乎成功构建了所有软件包,我得到了:

web_1| /usr/src/app/entrypoint.sh: 5: /usr/src/app/entrypoint.sh: nc: not found

如果我将#!/bin/sh更改为#!/bin/bash,则错误日志将更改:

web_1| /usr/src/app/entrypoint.sh: line 5: nc: command not found

Dockerfile:

FROM python:3.7-slim-buster

RUN apt-get update && apt-get -y dist-upgrade
RUN apt-get -y install build-essential libssl-dev libffi-dev libblas3 libc6 liblapack3 gcc python3-dev python3-pip cython3
RUN apt-get -y install python3-numpy python3-scipy 

# set working directory
WORKDIR /usr/src/app

COPY ./requirements.txt /usr/src/app/requirements.txt 
RUN pip3 install -r requirements.txt

# add entrypoint.sh
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh

RUN chmod +x /usr/src/app/entrypoint.sh

# add app
COPY . /usr/src/app

# run server
CMD ["/usr/src/app/entrypoint.sh"]

entrypoint.sh

#!/bin/sh

echo "Waiting for postgres..."

while ! nc -z web-db 5432; do
  sleep 0.1
done

rm -rf celery_logs/*

echo "PostgreSQL started"

python manage.py run -h 0.0.0.0

注意:该入口点配置曾经用于Alpine,现在已更改为Debian

我想念什么?

1 个答案:

答案 0 :(得分:2)

更新Dockerfile并追加

RUN apt install -y netcat

应该是

FROM python:3.7-slim-buster


RUN apt-get update && apt-get -y dist-upgrade
RUN apt-get -y install build-essential libssl-dev libffi-dev libblas3 libc6 liblapack3 gcc python3-dev python3-pip cython3
RUN apt-get -y install python3-numpy python3-scipy 
RUN apt install -y netcat