Home > Software design >  Docker Run Command as Sudo?
Docker Run Command as Sudo?

Time:04-25

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?

CodePudding user response:

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.

CodePudding user response:

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.

  • Related