Run sudo command with non-root user in Docker container

This is what I would do

FROM ubuntu:17.04

# Must have packages
RUN apt-get update && apt-get install -y vim nano zsh curl git sudo

# Install Oh my Zsh
RUN bash -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
RUN sed -i -- 's/robbyrussell/sonicradish/g' /root/.zshrc 

# Add none root user
RUN  useradd admin && echo "admin:admin" | chpasswd && adduser admin sudo
USER admin

Just create your non root user and add it to the sudoers group:

FROM ubuntu:17.04

RUN apt-get update
RUN apt-get install sudo

RUN adduser --disabled-password --gecos '' admin
RUN adduser admin sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER admin

Tags:

Docker

Bash

Sudo