skip to Main Content

Inside my dockerfile I have:

FROM ubuntu:latest
FROM python:latest

RUN sudo apt-get update
RUN apt-get install nmap

But I have a problem where the last line doesn’t work because of sudo, how may I fix this?

2

Answers


  1. The following works for me:

    RUN apt-get update && 
        apt-get install -y --no-install-recommends 
        nmap
    

    -y means automatic "yes" answer to all prompts and runs non-interactively.

    Login or Signup to reply.
  2. Since your first FROM statement doesn’t do anything and you’re already running as root, you can change your Dockerfile to

    FROM python:latest
    RUN apt-get update
    RUN apt-get install -y nmap
    

    Build and run with

    docker build -t myimage .
    docker run -it myimage /bin/bash
    

    Now you’re in a shell in the container. You can now run whoami to verify that you’re running as root and you can run nmap.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search