2

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?

2

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.

2
  • OK I didn't know that docker cp works recusively, that solves then the problem. commiting was in my mind, I just was looking for a quicker way (like cp method). Thank you. Shell access way will not work, cuz any way the container is not starting. – Mohammed Noureldin Aug 13 '17 at 20:55
  • shell access will work with nsenter if you dont want to commit and run the new image as a container overwriting the entrypoint – sgohl Aug 14 '17 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.