Docker commit 没有历史数据
Docker 大约 778 字现象
Docker
打包自己的新镜像commit
后,再启动新镜像没有历史数据了。
原镜像启动命令
docker run -d \
--name=redis1
-v $PWD/redis/data:/data \
-v $PWD/redis/mydata:/mydata \
redis:latest
镜像默认容器卷
使用inspect
查看
docker inspect redis:latest
输出:
[
{
"ContainerConfig": {
"ExposedPorts": {
"6379/tcp": {}
},
"Volumes": {
"/data": {}
},
"WorkingDir": "/data",
},
"DockerVersion": "20.10.7",
"Config": {
"Volumes": {
"/data": {}
},
"WorkingDir": "/data"
}
}
]
原因
commit
不会对映射的文件夹及Volumes
容器卷的文件夹进行打包。
所以案例中的redis
容器映射了两个文件夹中的数据都不会被打包进新镜像。
解决办法
如果需要把数据打包进容器中,则需要在非映射文件夹和非Volumes
文件夹中存储数据,可以docker cp
命令从宿主机拷贝进容器,或从Volumes
文件夹拷贝数据,再进行commit
。
阅读 318 · 发布于 2022-01-30
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Golang JSON Tag阅读 1629
-
HTML 禁止在移动端缩放阅读 675
-
Windows 下使用 Wireshark 抓取 HTTP2 加密数据包阅读 2191
-
Prometheus+Grafana+jmx_exporter 监控 Java 虚拟机阅读 219
-
JavaFX TextArea 按 Enter 键发送阅读 475
-
通过 Windows 远程桌面修改远程电脑密码阅读 125
-
Elasticsearch 出现 circuit_breaking_exception 异常阅读 12983
-
MongoDB 批量更新和删除字段阅读 2036
-
Prometheus+Grafana+nginx-prometheus-exporter 监控 Nginx阅读 375
-
PostgreSQL 修改字段属性阅读 1076