我有這個泊塢文件...Dockerfile不會使用sudo權限運行腳本,用戶
FROM ubuntu:14.04 MAINTAINER Sindhu S [email protected]
# 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"]
正如你可以看到它應該運行install.sh爲回溯用戶(該用戶有權利須藤)。基本上,腳本不應該以root身份運行,而應該以擁有sudo權限的用戶身份運行,因爲我們需要修改一些系統文件。
我曾嘗試用:
RUN ["/bin/bash", "-c", "sudo touch /etc/apt/sources.list.d/pgdg.list"]
和這個作品!
然而,當我有這樣一行:
RUN ["/bin/bash", "-c", "/home/scrollback/install.sh"]
在腳本中有一行:
$(sudo echo $apt_source > /etc/apt/sources.list.d/pgdg.list)
和我...
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
我該如何解決這個問題?