Docker Debian nc command not found

13,664

Update the Dockerfile and append,

RUN apt install -y netcat

It should be like,

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
Share:
13,664
8-Bit Borges
Author by

8-Bit Borges

Computers are fantastic. Minds are real (and elastic). Brains are evolutionary add-ons. Consciousness is raw. Think fields instead of neurons. Uncertainty is the law. This is not a simulation, Elon. It's easier to swallow a bug than a lie. If machines rise, we'll fly.

Updated on June 16, 2022

Comments

  • 8-Bit Borges
    8-Bit Borges almost 2 years

    When I build my Debian image from docker-compose, with the command $ docker-compose -f docker-compose-dev.yml build web, like so:

    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
    

    As though it appears to build all packages successfully, I'm getting:

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

    If I change #!/bin/sh to #!/bin/bash, error log changes:

    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
    

    Note: this entrypoint configuration used to work with Alpine, and now has changed to Debian.

    what am I missing?

    • OneCricketeer
      OneCricketeer over 4 years
      nc: command not found is the actual error
    • 8-Bit Borges
      8-Bit Borges over 4 years
      yes. I am trying to install apt-get install -y netcat. still building.
    • OneCricketeer
      OneCricketeer over 4 years
      By the way, this image works great. github.com/tiangolo/meinheld-gunicorn-flask-docker
    • OneCricketeer
      OneCricketeer over 4 years
      numpy and scipy should be installed with pip, and python3 has pip already, so don't need python3-pip
    • 8-Bit Borges
      8-Bit Borges over 4 years
      you mean in requirements.txt as well, or in Dockerfile?
    • 8-Bit Borges
      8-Bit Borges over 4 years
      feel free to update Dockerfile code in order to improve it, like you said. either on an answer os in the question itself. I'd approve
    • 8-Bit Borges
      8-Bit Borges over 4 years
      @cricket_007 I have some other scientific packages in requirements.txt, like pandas, matplotlib, scikitlearn. do you recommend me to move numpy ans scipy there too?
    • OneCricketeer
      OneCricketeer over 4 years
      Move whatever you need to run the app within requirements file, yes
  • 8-Bit Borges
    8-Bit Borges over 4 years
    I had done RUN apt-get update && apt-get -y dist-upgrade && apt-get install -y netcat. any different?
  • Anuradha Fernando
    Anuradha Fernando over 4 years
    No difference, it would install nc! and are you still experiencing the same issue?
  • OneCricketeer
    OneCricketeer over 4 years
    Its not really best practice to have multiple RUN lines like that
  • Anuradha Fernando
    Anuradha Fernando over 4 years
    @cricket_007 you mean that could add additional layers to the image?
  • OneCricketeer
    OneCricketeer over 4 years
    It will, yes. Also, rm the apt cache
  • David Maze
    David Maze over 4 years
    If the apt-get update gets cached but it's a week old, the apt-get install lines can fail (both Debian and Ubuntu fairly aggressively purge non-current packages from their repositories). It's important to apt-get update && apt-get install in the same RUN command to avoid this. ("Additional layers" isn't really a significant concern on its own.)
  • OneCricketeer
    OneCricketeer over 4 years
  • 8-Bit Borges
    8-Bit Borges over 4 years
    @cricket_007 rm -rf /var/lib/apt/lists/* after the last RUN apt-get?
  • Anuradha Fernando
    Anuradha Fernando over 4 years
    @DataGarden I think apt-get clean will do the same, you can run apt-get -s clean to do a simulation and see what are the locations will be cleared.
  • 8-Bit Borges
    8-Bit Borges over 4 years
    @AnuradhaFernando" Official Debian and Ubuntu images automatically run apt-get clean, so explicit invocation is not required.". From the link above.