gpt4 book ai didi

docker - 从图像中删除卷

转载 作者:行者123 更新时间:2023-12-02 18:32:04 25 4
gpt4 key购买 nike

当我使用一些 volumesdocker-compose 创建一个容器,然后提交该容器时,docker-compose 文件中的 volumes也会犯。有没有办法不提交图像中的卷?

使用下面的命令只能添加音量但不能删除它们:

docker commit -c 'VOLUME /foo' container_name image_name

谢谢。

最佳答案

更新(2018 年 4 月):在“How can I edit an existing docker image metadata?”中,Guido U. Draheim建议gdraheim/docker-copyedit ,一个可以编辑 docker 镜像元数据的 python 脚本。

这可以删除或覆盖图像元数据,包括体积。

命令是:

./docker-copyedit.py FROM image1 INTO image2 REMOVE ALL VOLUMES

2018年以来,同期now includes (来自 Aalex Gabi ):

For building a CI image with an embedded MySQL database snapshot I ended up using this solution: "Persist & share dev data in a Docker image with commit" from Steven Landow.

FROM mysql:5.7

ADD snapshots/default.sql /tmp/default.sql

# Using separate data folder outside of mysql image declared volume
# https://github.com/moby/moby/issues/3465
# https://medium.com/@stevenlandow/persist-share-dev-mysql-data-in-a-docker-image-with-commit-f9aa9910be0a
RUN mkdir /var/lib/mysql-no-volume

RUN set -exu ;\
MYSQL_ROOT_PASSWORD=root docker-entrypoint.sh --datadir /var/lib/mysql-no-volume &\
MYSQL_PID=$! &&\
timeout 22 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' localhost 3306 &&\
mysql -proot -e 'create database `mydb` collate "utf8mb4_general_ci"' &&\
mysql -proot mydb < /tmp/default.sql &&\
kill $MYSQL_PID &&\
tail --pid=$MYSQL_PID -f /dev/null # Using tail to wait for PID to end https://unix.stackexchange.com/questions/427115/listen-for-exit-of-process-given-pid

# Using separate data folder outside of mysql image declared volume
# https://github.com/moby/moby/issues/3465
# https://medium.com/@stevenlandow/persist-share-dev-mysql-data-in-a-docker-image-with-commit-f9aa9910be0a
CMD ["--datadir", "/var/lib/mysql-no-volume"]

关于docker - 从图像中删除卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39570313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com