I am trying to create a multi-stage build in docker that simply runs non-root crontabs that write to the extent accessible from outside the container. I have two problems with permissions: with external access in appearance and with cron:
the first build in the dockerfile creates a non-root user entry-point user image and su-exec useful for fixing permissions with a volume!
the second build in the same dockerfile used the first image to start the crond process, which is usually written to the / backup folder.
docker-compose.yml file to create a docker file:
version: '3.4' services: scrap_service: build: . container_name: "flight_scrap" volumes: - /home/rey/Volumes/mongo/backup:/backup
In the first step of DockerFile (1), I try to adapt denis bertovic's answer to an alpine image
My docker-entrypoint.sh for permission fix:
#!/usr/bin/env bash chown -R scrapy . exec su-exec scrapy " $@ "
The second step (2) will start the cron service to write to the / backup folder set as volume
The crontab file, which usually creates a test file in the /backup volume folder:
* * * * * touch /backup/testCRON
DEBUG Phase:
Enter my image using bash, it seems that the image starts the scrapy user correctly:
uid=1000(scrapy) gid=1000(scrapy) groups=1000(scrapy)
The crontab -e command also provides the correct information.
But the first error , cron does not start correctly when I cat /var/log/cron.log I have permission denied
crond: crond (busybox 1.27.2) started, log level 8 crond: root: Permission denied crond: root: Permission denied
I also have a second error when I try to write directly to the / backup folder using the touch /backup/testFile . The volume /backup folder remains accessible only with root privileges, I donβt know why.
source share