On this Postgres Docker image, I'm copying a couple of files over to configure the container.
(1) init.sh - copies to Docker entrypoint (2) data.txt - containing sensitive information
At the end of init.sh I want to delete data.txt, but the file never gets deleted.
docker-compose.yml
version: '3.6'
services:
postgres_test:
container_name: postgres_13_3
image: postgres_13_3
restart: unless-stopped
build:
context: ./postgres
dockerfile: postgres_13_test.dk
environment:
POSTGRES_PASSWORD: 'test'
postgres_13_test.dk
FROM postgres:13.3-alpine3.14
# copy files over
COPY ./data.txt /tmp/data.txt
RUN chmod 777 /tmp/data.txt
COPY ./init.sh /docker-entrypoint-initdb.d/init.sh
init.sh
# ... do other things first
# then in the end, delete file
rm -rf /tmp/data.txt # <-- file never gets deleted
What am I missing ?
UPDATE
Now rebuild the conatainer fesh w/ --no-cache, and now it shows this error message
postgres_13_3 | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sh
postgres_13_3 | rm: can't remove '/tmp/data.txt': Operation not permitted
How can I prevent this error ?