2

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?

3
  • 1
    Tried on Windows version 22.0.5 of Docker and it works, the folder is created with the correct permissions. I checked that on Ubuntu the latest version is 22.0.5. Try to update the docker engine, instruction here Commented Aug 17, 2023 at 10:36
  • 1
    Is this the same problem as Docker not keeping chown user settings? That has a reference to a Launchpad issue. Commented Aug 17, 2023 at 10:52
  • 1
    (Reading the Dockerfile, my first response would be to tell you to not create a home directory, since that's not usually useful in a single-process container, and definitely not to install sudo. But that might be secondary to your issue.) Commented Aug 17, 2023 at 10:53

1 Answer 1

0

Thanks for the answers. Solved by making user with no home directory as @DavidMaze suggested.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.