0

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?

Jinwoo Nam
  • 17
  • 4
  • You need to modify the image's Dockerfile to not include the file (usually not delete it, but rather arrange for it to not exist at all) and then `docker build` the new image. "Commit" should not be part of your Docker vocabulary. Do you have a [mcve] demonstrating the problem? – David Maze Aug 08 '22 at 10:01
  • what is the issue with my answer? – btafarelo Aug 08 '22 at 10:11

1 Answers1

-1

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

btafarelo
  • 601
  • 3
  • 12