对于下面的 dockerfile:
FROM buildpack-deps:buster
RUN groupadd -r someteam --gid=1280 && useradd -r -g someteam --uid=1280 --create-home --shell /bin/bash someteam
# Update and allow for apt over HTTPS
RUN apt-get update && \
apt-get install -y apt-utils
RUN apt-get install -y apt-transport-https
RUN apt update -y
RUN apt install python3-pip -y
# switch user from 'root' to ‘someteam’ and also to the home directory that it owns
USER someteam
RUN pwd
USER
只更改用户而不是主目录
编辑:
Step 11/14 : WORKDIR $HOME
cannot normalize nothing
如何将主目录更改为/home/someteam
?
最佳答案
您可以使用 dockerfile 中的 WORKDIR
更改用户目录,这将成为工作目录。因此,无论何时创建容器,工作目录都将是传递给 Dockerfile 中的 WORKDIR
指令的目录。
工作目录
WORKDIR 指令的 Dockerfile 引用
For clarity and reliability, you should always use absolute paths for your WORKDIR. Also, you should use WORKDIR instead of proliferating instructions like RUN cd … && do-something, which are hard to read, troubleshoot, and maintain.
FROM buildpack-deps:buster
RUN groupadd -r someteam --gid=1280 && useradd -r -g someteam --uid=1280 --create-home --shell /bin/bash someteam
# Update and allow for apt over HTTPS
RUN apt-get update && \
apt-get install -y apt-utils
RUN apt-get install -y apt-transport-https
RUN apt update -y
RUN apt install python3-pip -y
# switch user from 'root' to ‘someteam’ and also to the home directory that it owns
USER someteam
WORKDIR /home/someteam
使用 $HOME 会导致错误。
When you use the USER directive, it affects the userid used to start new commands inside the container.Your best bet is to either set ENV HOME /home/aptly in your Dockerfile, which will work dockerfile-home-is-not-working-with-add-copy-instructions
关于Dockerfile - 用于切换主目录的 Docker 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57226929/