1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Docker - Permission Denied when Write Files to Host

Last updated at Posted at 2019-08-28

1. Dockerfile

I created a normal user JohnnyChu to run the program in docker.
It will write a log file in /data/log inner container and container volume bind the host /foo/log. Now, it will occur permission denied problem.

# build stage
FROM golang:1.12.9-alpine AS build-env
RUN apk update -qq && apk --no-cache add git gcc g++
COPY . /src/
ARG BUILD_ENV
RUN cd /src && go build -tags ${BUILD_ENV} -o /src/dist/app

# final stage
FROM alpine:3.10.2
WORKDIR /app/
COPY --from=build-env /src/dist/ /app/
RUN addgroup -S JohnnyChu && adduser -S JohnnyChu -G JohnnyChu && chown -R JohnnyChu:JohnnyChu /app/
USER JohnnyChu
EXPOSE 8080
ENTRYPOINT ["./app"]

2. Run

# docker run -v /foo/log:/data/log  ... --name boo ...

2. Check User UID:GID inner Container.

# docker exec -it boo sh
/app $ cat /etc/passwd
...
...
guest:x:405:100:guest:/dev/null:/sbin/nologin
nobody:x:65534:65534:nobody:/:/sbin/nologin
JohnnyChu:x:100:101:Linux User,,,:/home/JohnnyChu:/sbin/nologin <--- UID:100 GID:101

3. Chown Host's Log Folder

# chown -R 100:101 /foo/log

4. Restart Container

# docker restart boo

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?