I am trying to build a docker image and create user "builder". This is the extract of the Dockerfile:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y sudo
RUN useradd -ms /bin/bash builder
RUN ls -al /home
The home directory is created with root as owner. Docker build command output:
Step 7/15 : RUN useradd -ms /bin/bash builder
---> Running in cdb06ab940c4
Removing intermediate container cdb06ab940c4
---> 3b4ee1d9f9d0
Step 8/15 : RUN ls -al /home
---> Running in 03b7a9bee771
total 12
drwxr-xr-x 1 root root 4096 Aug 17 07:14 .
drwxr-xr-x 1 root root 4096 Aug 17 07:14 ..
drwxr-x--- 2 root root 4096 Aug 17 07:14 builder
I have tried adding chown after addusr :
"RUN useradd -ms /bin/bash builder && chown -R builder:builder /home/builder
but the home directory is still owned by root.
If I run ubuntu:22.04 with
docker run -it ubuntu:22.04
I can create the user with command "useradd -ms /bin/bash builder" and the home directory will have correct permissions
I am using ubuntu 22.04. Docker version:
Client:
Version: 20.10.25
API version: 1.41
Go version: go1.18.1
Git commit: 20.10.25-0ubuntu1~22.04.1
Built: Fri Jul 14 21:58:09 2023
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.25
API version: 1.41 (minimum version 1.12)
Go version: go1.18.1
Git commit: 20.10.25-0ubuntu1~22.04.1
Built: Thu Jun 29 21:21:05 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.2
GitCommit:
runc:
Version: 1.1.7-0ubuntu1~22.04.1
GitCommit:
docker-init:
Version: 0.19.0
GitCommit:
Any hints?
sudo. But that might be secondary to your issue.)