Reputation: 1
For the below 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
just change the user but not the home directory
Step 11/14 : WORKDIR $HOME
cannot normalize nothing
How to change home directory to /home/someteam
?
Upvotes: 9
Views: 25417
Reputation: 60074
You can change user directory using WORKDIR
in the dockerfile, this will become the working directory. So whenever you created the container the working directory will be the one that is pass to WORKDIR
instruction in Dockerfile.
WORKDIR
Dockerfile reference for the WORKDIR instruction
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
using $HOME will cause error.
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
Upvotes: 8