大网数据广告活动
服务器运维问答

How to access Docker container's data when they are not mapped to a volume?

· 52CE 我爱测

How to access Docker container's data ( not mapped to any volume ), when the container failed to start? Let us say I started the container like this: docker run -it --name testContainer ubuntu /entrypoint.sh and the entrypoint.sh…

问题原文

原帖链接 · Mohammed Noureldin · CC BY-SA 3.0

How to access Docker container's data (not mapped to any volume), when the container failed to start?

Let us say I started the container like this:

docker run -it --name testContainer ubuntu /entrypoint.sh

and the entrypoint.sh for some reason later fails to stay running (in other word the container practically doesn't start), but I want to get access to some date stored in that container (eg. /var/www/html/XYZ), How can I do that?

已采纳解答

原帖链接 · sgohl · CC BY-SA 3.0

You can docker cp on a stopped container:

docker cp containername:/root .

this will copy all the contents (recursive) from the folder /root within the container to your current dir $PWD on the host into ./root

If you need shell access, on way could be https://github.com/jpetazzo/nsenter

Another way would be to commit the stopped container into a temporary image and then run a container from this image with an available shell:

docker commit containername tmpimage

docker run -it tmpimage /bin/bash

If the image has an ENTRYPOINT defined, you have to replace it:

docker run -it --entrypoint=/bin/bash tmpimage

Change bash to ash or sh if alpine or other distro not having bash.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。