# Docker data saved in persistent storage

**URL:** <https://deeptalk.lambda.ai/t/docker-data-saved-in-persistent-storage/3811>\
**Category:** Uncategorized\
**Created:** [June 23, 2023, 4:06pm UTC](https://deeptalk.lambda.ai/t/docker-data-saved-in-persistent-storage/3811 "2023-06-23T16:06:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addavox](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@addavox](https://deeptalk.lambda.ai/u/addavox)\
**Post date:** [June 23, 2023, 4:06pm UTC](https://deeptalk.lambda.ai/t/docker-data-saved-in-persistent-storage/3811/1 "2023-06-23T16:06:06Z")

</div>

ML Training

I know that we can store our models, training data, etc in persistent storage so that we don’t have to load it every time we spin up a new instance.

Can we do the same with Docker data (/var/lib/docker/)?

I assume we are getting our own VM but not sure if we’ll have the root privilege to symlink our /var/lib/docker dir to persistent storage.

I have not signed up with Lamba Labs yet so not having to rebuild our docker environment every time we spin up a new instance will help in the decision process.

Thanks

---

<div class="post-metadata">

**Author:** ![mpapili](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@mpapili](https://deeptalk.lambda.ai/u/mpapili)\
**Post date:** [June 23, 2023, 6:53pm UTC](https://deeptalk.lambda.ai/t/docker-data-saved-in-persistent-storage/3811/2 "2023-06-23T18:53:34Z")

</div>

In short, yes you can definitely do this and you have root access to your instances. Less of a headache than symlinking (for me, largely preference) is just telling Docker that you’ve got your own preferred `data-root` location:

I’ve just run through this myself on two Lambda Cloud GPU Instances just to make sure I was giving you accurate info, but if interested:

**First I set up a Filesystem:**  
(Important to point out, Lambda notes this is a beta feature on their website. I can only answer from personal experience, but the stability/experience has been excellent to me):  
 ![Screenshot from 2023-06-23 14-19-52](https://us1.discourse-cdn.com/flex019/uploads/deeptalk/original/1X/8beb054f04f719cfff4e31717a20f89e01b9ebac.png)

**Started up an Instance in the same location as my filesystem:**

 ![Screenshot from 2023-06-23 14-23-03](https://us1.discourse-cdn.com/flex019/uploads/deeptalk/original/1X/48e97a31190cbabb69c2a2b894aa74af3508c934.png)

(A6000 instance if curious, though it does not impact this test)

```auto
# SSH in normally:
ssh ubuntu@<IP> -i <YOUR_KEY>.pem 

```

Check that our filesystem is mounted:

```auto
ubuntu:~$ ls -l
total 0
drwxr-xr-x 2 ubuntu ubuntu 4096 Jun 23 18:20 TestFilesystem

```

Set Docker’s root to your desired filesystem (should be mounted at `/home/ubuntu/<YOUR_FS_NAME>`) and bounce:

```auto
echo '{ "data-root": "/home/ubuntu/TestFilesystem" }' | sudo tee /etc/docker/daemon.json && sudo systemctl restart docker

```

Pulling down a Docker image just to test/demonstrate:

```auto
sudo docker pull fedora
sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
fedora latest 6126bb20b2b5 2 days ago 190MB

```

At this time I completely terminate the first instance, but of course I still have my persistent storage.

Then…

**Started up a completely fresh/new instance:**

 ![Screenshot from 2023-06-23 14-44-30](https://us1.discourse-cdn.com/flex019/uploads/deeptalk/original/1X/8e1901309a3e1c7e012fbefb8e56b6750e57a4b3.png)

ssh into THIS Instance and:

```auto
# instantly run the same one-liner as last time
echo '{ "data-root": "/home/ubuntu/TestFilesystem" }' | sudo tee /etc/docker/daemon.json && sudo systemctl restart docker

```

Checking and making sure our images are still present:

```auto
# are all of our images still there?
ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
fedora latest 6126bb20b2b5 2 days ago 190MB

```

Works like a charm. I did notice that when storing docker images in these separate filesystems you may need to set your storage driver in that Docker JSON configuration, example:

```auto
{
    "data-root":"/home/ubuntu/TestFilesystem",
    "storage-driver": "devicemapper"
}

```

-however I did not need to do this for the Fedora Image in this demonstration, just something of note. I’m not fully aware of the differences in the storage type/drivers these separate filesystems use.

**“TL;DR:”**  
-but it all works for me from these basic tests without issue. All works out the box at the cost of a one-liner on-boot which sounds like it’s what you were after.

---

<div class="post-metadata">

**Author:** ![addavox](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@addavox](https://deeptalk.lambda.ai/u/addavox)\
**Post date:** [June 23, 2023, 8:54pm UTC](https://deeptalk.lambda.ai/t/docker-data-saved-in-persistent-storage/3811/3 "2023-06-23T20:54:58Z")

</div>

@mpapili Amazing answer!!! Thank you very much. I will be spinning up my first instance next week.
