To use fixuid, follow these four steps in your Dockerfile:
1. Create a non-root user and group
Create a user/group with a fixed UID/GID (1000:1000 is recommended). Use the command appropriate for your base image:
Alpine:
RUN addgroup -g 1000 docker && \
adduser -u 1000 -G docker -h /home/docker -s /bin/sh -D docker
Debian / Ubuntu:
RUN addgroup --gid 1000 docker && \
adduser --uid 1000 --ingroup docker --home /home/docker --shell /bin/sh --disabled-password --gecos "" docker
Fedora:
RUN groupadd -g 1000 docker && \
useradd -u 1000 -g docker -d /home/docker -s /bin/sh docker
2. Install the fixuid binary and configure it
Download the binary, set the setuid bit (required), and create the configuration file at /etc/fixuid/config.yml. This step requires curl and must be run as root.
RUN USER=docker && \
GROUP=docker && \
curl -SsL https://github.com/boxboat/fixuid/releases/download/v0.6.0/fixuid-0.6.0-linux-amd64.tar.gz | tar -C /usr/local/bin -xzf - && \
chown root:root /usr/local/bin/fixuid && \
chmod 4755 /usr/local/bin/fixuid && \
mkdir -p /etc/fixuid && \
printf "user: $USER\ngroup: $GROUP\n" > /etc/fixuid/config.yml
3. Set the user and entrypoint
Switch to the user created in step 1 and set fixuid as the entrypoint.
USER docker:docker
ENTRYPOINT ["fixuid"]
4. Run the container with host UID/GID
When running the container, pass your host's UID/GID using the -u flag.
docker run --rm -it -u 1000:1000 <image name> sh
# Example snippet for a Dockerfile
RUN USER=docker && \
GROUP=docker && \
curl -SsL https://github.com/boxboat/fixuid/releases/download/v0.6.0/fixuid-0.6.0-linux-amd64.tar.gz | tar -C /usr/local/bin -xzf - && \
chown root:root /usr/local/bin/fixuid && \
chmod 4755 /usr/local/bin/fixuid && \
mkdir -p /etc/fixuid && \
printf "user: $USER\ngroup: $GROUP\n" > /etc/fixuid/config.yml
USER docker:docker
ENTRYPOINT ["fixuid"]