作者:真相一个 | 来源:互联网 | 2023-01-31 19:41
我正在为本地开发需求创建一个docker文件.该文件创建一个user
帐户user
作为密码.我认为应该工作的路线是:
# allow writes to the home directory
RUN echo "user" | sudo -S chmod 777 ~
但是,当我以交互方式运行图像时,它似乎失败了,我看到了这条消息:
mkdir: cannot create directory ‘/home/.meteor-install-tmp’: Permission
denied
当我sudo -S chmod 777 ~
在容器内运行时,它可以工作.
这是完整的脚本:
# docker build -t timebandit/meteor-1-5 --rm .
# docker run -v /host/path:/home/code -it timebandit/meteor-1-5 bash
FROM ubuntu:xenial
# update the system
RUN apt-get update && apt-get -y install curl \
sudo \
apt-utils \
locales \
nano
# Set the locale
RUN sudo sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/'
/etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# set the root password
RUN echo "root:root" | chpasswd
# create a user
RUN useradd -ms /bin/bash user
RUN adduser user sudo
RUN echo 'user:user' | chpasswd
ENV HOME=/home
WORKDIR $HOME/user
USER user
# allow writes to the home directory
ARG user_pass
RUN echo $user_pass | sudo --stdin chmod 777 /home
# install meteor
RUN echo $user_pass | sudo curl https://install.meteor.com/ | sh
BMitch..
5
我建议sudo
完全跳过,因为您可以使用Dockerfile更改用户:
....
# allow writes to the home directory
USER root
RUN chmod 777 /home
USER user
....
在图像中添加sudo意味着攻击者可以使用它.只要您需要以root用户身份返回容器,就可以使用该选项更改docker run
或docker exec
命令的用户-u root
.
1> BMitch..:
我建议sudo
完全跳过,因为您可以使用Dockerfile更改用户:
....
# allow writes to the home directory
USER root
RUN chmod 777 /home
USER user
....
在图像中添加sudo意味着攻击者可以使用它.只要您需要以root用户身份返回容器,就可以使用该选项更改docker run
或docker exec
命令的用户-u root
.