I know that the docker image is read-only. Therefore, deleting the file inside base-image within container does not change the size of docker. (result of docker ps -s
)
I wanted to reduce image size, but it's already committed, and I can't reduce it. Because committed image is read-only. How can I delete the files inside the image? Or is there a way to commit image read-and-write mode instead of read-only?
CodePudding user response:
The way to achieve it is creating a new image without the file.
After you have deleted the file(s) you want to inside the running container, run:
docker export <container id> -o <filename>
and
docker import <filename> <image name>
Doing it you will get a new image without those files.
To delete the files:
docker exec -ti <container id> /bin/bash
and delete the files
CodePudding user response:
You can get benefitted from docker multi stage builds, also you can create a new Dockerfile and use your base image there and remove your files then prepare a new image.
Example:
FROM yourrepo/yourimage
RUN rm -r /filesToRemove/