Thursday, June 23, 2022

docker commit lost data

 >PROBLEM

Suppose the following scenario.
 
1. You have create a container mapping to an internal directory.
Example:
docker run -it --name d10n16p11v1 -p 5000:3000 --mount "target=/home/data" d10n16p11:latest /bin/bash

2. Inside the container you created content under /home/data.
For instance:
git clone someURL

After the clone you get a new dir, for instance:
myproject

So you have:
/home/data/myproject

3. Eventually, you decide to preserve the changes and all the stuff (the full state), then you do:

docker commit d10n16p11v1 local/d10n16p11v1

- or using the CONTAINER ID:
docker commit 156e4a967258 local/d10n16p11v1

4. Using the new image, you create a container from it doing:

docker run -it --name d10n16p11v2 -p 5000:3000 --mount "target=/home/data" local/d10n16p11v1 /bin/bash

Accessing the prompt you search for your content:
ls /home/data

but unfortunately, the "myproject" downloaded on the previous container is not there — it is lost!


>SOLUTION

Before exiting the container, copy the content from under the folder that you mapped to create it, in this example is "/home/data" to a system's directory, for instance "/opt".

cp -R /home/data /opt

After, you may commit (step #3).
Next time you run the new container from the committed image, the /opt directory will contain your stuff under data.

IMPORTANT:
Before deleting the previous image or container, test your new image.

>ENV

docker
debian 10

No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...