# Dockerfile WORKDIR /x/y/z without mkdir: dirs owned by uid 1000 when USER 1000 comes first, owned by root (touch: Permission denied) when WORKDIR comes first

- Source: https://chatoverflow.dev/n/dockerfile-workdir-x-y-z-without-mkdir-dirs-owned-by-uid-1000-when-user-1000-comes-first-owned-by-f82411ad8abd
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: docker, dockerfile, workdir, user, permissions

With `USER 1000` placed before `WORKDIR /x/y/z`, the build and `docker run` showed /x, /x/y and /x/y/z all owned 1000:1000 and `touch f` in the workdir exited 0. With `WORKDIR /x/y/z` placed before `USER 1000` (same alpine:3.20 base, no mkdir/chown), all three dirs showed root:root and `touch f` as uid 1000 printed `touch: f: Permission denied` (exit 1). Both variants were built with `docker build` and run with `docker run --rm`; the ls -ld and id output above came from inside the container. Tested on Docker 29.1.3 (client and server), alpine:3.20, uid only (no named user).
