Dockerfile won't run script as user with sudo rights

I have this Docker file…

FROM ubuntu:14.04 MAINTAINER Sindhu S sindhu@alum.hackerschool.org
# RUN apt-get update && apt-get -y install sudo wget bash git && rm -rf /var/cache/apt-get/archives/*
RUN adduser --disabled-password --gecos "" scrollback  
RUN adduser scrollback sudo  
RUN echo 'scrollback ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers RUN mkdir -p /home/scrollback && chown -R scrollback:scrollback /home/scrollback
WORKDIR /home/scrollback/ 
ADD https://raw.githubusercontent.com/sindhus/scrollback/install-script/tools/install.sh /home/scrollback/install.sh 
RUN chown scrollback:scrollback install.sh
RUN chmod +x install.sh
USER scrollback RUN ["/bin/bash", "-c", "/home/scrollback/install.sh"]

As you can see its supposed to run the install.sh as scrollback user (this user has sudo rights). Basically the script shouldn’t run as root but should run as user with sudo rights because there are some system files we need to modify.

  • Running Unity3d for automated builds inside a docker container
  • prior storage driver “devicemapper” failed: exit status 1 in docker
  • I config docker bridge but now the network in container can't work will
  • docker container port accessed from another container
  • NGINX + PHP-FPM - Should I keep them in separate containers or not?
  • Docker + Marathon : how to do a port mapping ?
  • I have tried with:

    RUN ["/bin/bash", "-c", "sudo touch /etc/apt/sources.list.d/pgdg.list"]

    and this works!

    Yet when I have this line:

    RUN ["/bin/bash", "-c", "/home/scrollback/install.sh"]

    in the script there is a line:

    $(sudo echo $apt_source > /etc/apt/sources.list.d/pgdg.list)

    and I get…

    Adding Postgres' deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main source to your software sources list (need root user rights)..
    ./install.sh: line 136: /etc/apt/sources.list.d/pgdg.list: Permission denied

    How can I fix this?

  • Performance and reliability when using multiple Docker containers VS standard Node cluster
  • Error response from daemon: Container CONTAINER_NAME is not running
  • How can one influence the order of RUN commands in a Dockerfile?
  • Host redirection not working boot2docker
  • Owncloud 8 with Docker behind nginx available through subdirectory
  • Docker: "Unknown instruction: VIRTUALENV'
  • One Solution collect form web for “Dockerfile won't run script as user with sudo rights”

    It is not a good practice using sudo inside a bash script. Instead use the command directly and run your script with sudo. Thus, your script (and the programs launched inside) will be launched with root privileges.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.