Home > Software engineering >  Cannot change permissions for 'RUN chmod x /app-entrypoint.sh' in Dockerfile
Cannot change permissions for 'RUN chmod x /app-entrypoint.sh' in Dockerfile

Time:12-20

I have the following Dockerfile

FROM docker.io/bitnami/jasperreports:7-debian-10
COPY custom-entrypoint.sh /app-entrypoint.sh
RUN  chmod  x /app-entrypoint.sh

I'm trying to build a new image like this

docker build -t registry/jasperserver:latest .

I'm getting this error

 => ERROR [3/7] RUN  chmod  x /app-entrypoint.sh                                                                                                                                                                                                                                                                                            0.4s
------                                                                                                                                                                                                                                                                                                                                           
 > [3/7] RUN  chmod  x /app-entrypoint.sh:
#8 0.380 chmod: changing permissions of '/app-entrypoint.sh': Operation not permitted
------
executor failed running [/bin/sh -c chmod  x /app-entrypoint.sh]: exit code: 1

Why can't I change the permissions of /app-entrypoint.sh?

Edited:

This is the output docker info yields

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)
  compose: Docker Compose (Docker Inc., v2.0.0-rc.3)
  scan: Docker Scan (Docker Inc., v0.8.0)

Server:
 Server Version: 20.10.8
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e25210fe30a0a703442421b0f60afac609f950a3
 runc version: v1.0.1-0-g4144b63
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.10.60.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.63GiB
 Name: docker-desktop
 ID: 6IIP:AJPF:HJJU:4J2X:MWJM:YIUH:ZXLZ:XHG5:E7SZ:RYKB:HBSR:RMMU
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/

CodePudding user response:

The COPY step will create the file with the uid/gid of 0:0 (root:root) within the / directory where normal users have no access. And the selected base image is configured to run as uid 1001. Probably the easiest is to switch back to root temporarily to run that step.

FROM docker.io/bitnami/jasperreports:7-debian-10
USER root
COPY custom-entrypoint.sh /app-entrypoint.sh
USER 1001
RUN  chmod  x /app-entrypoint.sh

Alternatively, you can copy the script to a directory where the user has access with the right ownership on the file. Without pulling the image, I suspect /opt/bitnami/scripts may have different permissions:

FROM docker.io/bitnami/jasperreports:7-debian-10
COPY --chown=1001 custom-entrypoint.sh /opt/bitnami/scripts/app-entrypoint.sh
RUN  chmod  x /opt/bitnami/scripts/app-entrypoint.sh
  • Related