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?
You can
docker cp
on a stopped container: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.