Hello,
I have created a PHP container and now I want to change the permissions of the files in the /var/www directory, but these changes should be permanent and not lost when the container is shut down or restart. What should I do?
Thank you.
Share and learn in the Docker community.
Hello,
I have created a PHP container and now I want to change the permissions of the files in the /var/www directory, but these changes should be permanent and not lost when the container is shut down or restart. What should I do?
Thank you.
A re-start shouldn’t change a file in a container, only a re-create.
If you want a file to survive a container re-create, you need to use a bind mount from host or a Docker volume.
Or do the changes in Dockerfile to have them included during image creation.
Hello,
Thank you so much for your reply.
So there’s no way I can change the permissions of a file or directory and have it remain after a shutdown or restart?
The base for a container is an image, created with Dockerfile. When starting the container, the image is used as base, an overlay filesystem is created, which contains file (permission) changes. Those files can also be stored via bind mount or volume on host directly.
Changes of the running container from the overlay file system are lost, when you delete the container or update the container with an updated image.
They continue to exist if you just stop/shutdown/start the container.
Docker volumes can get lost when you (stop and) remove the container with according flags.
Thanks again.
I changed the permissions of a file and shut down the container and restarted it. The changes were lost.
How did you shut it down? Also share your run command or compose file.
Hello,
I did:
docker compose down CONTAINER_NAME
The compose file is:
services:
portal:
container_name: portal
build:
context: /home/jason/portal/
dockerfile: Dockerfile
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING="true"
- USER_ID=${USER_ID:-999}
- GROUP_ID=${GROUP_ID:-995}
user: "${USER_ID:-999}:${GROUP_ID:-995}"
volumes:
- /home/docki/dev/portal-view:/app
- /app/node_modules
- /app/.next
ports:
- "127.0.0.1:3000:3000"
deploy:
resources:
limits:
cpus: '4.0'
memory: 4G