# Docker in Incus with Incus Volumes ("Get my" Revisited)

**URL:** https://discussion.scottibyte.com/t/docker-in-incus-with-incus-volumes-get-my-revisited/458
**Category:** Uncategorized
**Created:** [August 4, 2024, 6:43pm UTC](https://discussion.scottibyte.com/t/docker-in-incus-with-incus-volumes-get-my-revisited/458 "2024-08-04T18:43:38Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![scott](https://discussion.scottibyte.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://discussion.scottibyte.com/u/scott)
#### Post date: [August 4, 2024, 6:43pm UTC](https://discussion.scottibyte.com/t/docker-in-incus-with-incus-volumes-get-my-revisited/458/1 "2024-08-04T18:43:38Z")

</div>

This is a follow-on from my “[Docker in Incus is Awesome](https://www.youtube.com/watch?v=jZ9OZfKeI9M)” tutorial. This time we show how to move the persistent data from Brian’s “Get my” application to an incus volume. Incus volumes are a way to add storage to any container, but in this example we are using them for Docker OCI application containers.

We start with creating the MongoDB incus OCI container the same way as last time:

```auto
incus create docker:mongo:4.4 get-my-db

```

Create the incus OCI container for the “Get my” application:

```auto
incus create docker:bmcgonag/get_my:latest get-my -c environment.MONGO_URL=mongodb://get-my-db

```

Last time we created a folder on the incus host to contain the database persistently. Then we provided a “disk” mapping in incus which works like the volume mapping in docker compose. This command WHICH WE WON’T USE THIS time was:

```auto
incus config device add get-my-db mongodb disk source=/home/scott/get-my-data path=/data/db shift=true

```

Instead, this time we will be creating an incus storage volume in the incus default storage pool and mapping it to the MongoDB OCI container we created above.

Whenever you create an incus container, you are creating a volume. That means that incus containers, incus virtual machines, and these new incus OCI (Docker) containers are all volumes in your storage pool. You can list all of the volumes in your default storage pool:

```auto
incus storage volume list default

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/8/82797e6a6d36ec404a15d4205f430952514603bc.jpeg)

Since each time you create a container, incus reaches out to [linuxcontainers.org](http://linuxcontainers.org) to download an image to create the container, you may have many image volumes that are not being used. This is by design to speed the creation of future containers by using locally cached copies in your storage pool rather than having to do a download each time.

These images take up some space in the storage pool, but is not generally a major concern.

We are now going to create the storage volume to store the “Get my” database in our default storage pool with this command:

```auto
incus storage volume create default get-my-data

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/7/7cbec3c74ab86106730810c604f4d7e45dff8c3e.png)

If you now do another listing of the storage volumes, you will see the get-my-data volume as well as the get-my and get-my-db container volumes:

```auto
incus storage volume list default

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/a/a7dfb5dda3970a711577a05769f581e753d08c55.png)

To associate the custom volume get-my-data with the incus OCI database container:

```auto
incus storage volume attach default get-my-data get-my-db /data/db

```

Recall that the path /data/db is where MongoDB places its database files. That path is mapped to the volume making the data persistently stored between runs.

In order to make the application reachable from your LAN, we need to set up a port proxy which is the incus equivalent of a port forward. This command makes the application accessible from the address of the incus server on port 3000. You can change the “listen” port to any port your prefer, but you cannot change the “connect” port because that is what the application expects:

```auto
incus config device add get-my hostport3000 proxy connect="tcp:127.0.0.1:3000" listen="tcp:0.0.0.0:3000"

```

You can now start the database:

```auto
incus start get-my-db

```

Wait a few moments and start the application:

```auto
incus start get-my

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/f/f553480a434994f684d1e3e74b8f8453ba02c144.jpeg)

You can examine the storage utilization of the custom volume to see how much data is being used for the database:

```auto
incus storage volume info default get-my-data 

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/2/2f92a04baabd2f368c2f2f85d284bf5418a837c1.png)

In the video, I accessed my get-my application at the address of my incus server on port 3000.  
I registered my admin account in get-my and I created a list named “grocery” and I put a couple items in my grocery list.

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/8/864718f84856bcddd80d5e173b793291c36bf8a1.png)

If we then go back to the terminal and list the volume info, you will see the increase in the storage utilization of the volume:

```auto
incus storage volume info default get-my-data 

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/5/5c5e36912faead760b414cf703c122c55440be4b.png)

There is another command you can use to list information about the custom volume:

```auto
incus storage volume show default get-my-data

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/7/7f49e841d160a4ccc3a6dd91762aaa3c75a54a3d.jpeg)

You can also edit the volume data:

```auto
incus storage volume edit default get-my-data

```

As shown in the video, this will enter the nano editor and you can create a description for the volume:

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/4/481997e1c874062cce79f52db6c837eaba15ff38.jpeg)

Do a CTRL O and enter to save the file out and a CTRL X to exit the nano editor.

Now if you do a listing of the volumes, you will see the new description:

```auto
incus storage volume list default

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/5/5707592cc4b717e0c138d6b8f7d518c92bf89ae9.png)

You can connect more than one container to a custom volume. Just be aware that there is no file locking unless the application has it built in. In the video I created an Ubuntu container:

```auto
incus launch images:ubuntu/24.04 Test

```

Next, connect the container “Test” to our volume:

```auto
incus storage volume attach default get-my-data Test /data/db

```

If you do a shell command into the new Test container, you can see the database data in the /data/db folder:

```auto
incus shell Test

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/4/4fb82497be53ce751abed34cf450752a26f7d744.jpeg)

If you exit out of the Test container and do a listing of your incus containers, you will see the Test container, the get-my container and the get-my-db container.

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/0/03e9645695b5222a8f4043a8f2719d21485b7f85.jpeg)

You can backup a custom volume just like a container with an incus export command. This backup can be moved to another incus server with an import command or just kept for archival/backup purposes.

```auto
incus storage volume export default get-my-data get-my-data.tar.gz

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/8/87ecd9cf5cdc0047cb543cd95380a5682325cbdf.png)

We can import the backup as well. Note that you cannot import to the same volume name unless you delete the volume of the same name first.

```auto
incus storage volume import default get-my-data.tar.gz get-my-data-2

```

Now, if I list the volumes:

```auto
incus storage volume list default

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/6/6f7a9e2863a2823ed5c6a922e549fcd865aa45bb.png)

Note above that the “get-my-data” volume has two connections. One of them is get-my-db and the other is Test.

You can delete a storage volume, but it must not be used by any container or deletion is not allowed.

```auto
incus storage volume delete default get-my-data-2

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/9/9545e6426cd54b38f18494ed847938e2ce506262.png)

Incus custom volumes can be snapshotted to provide point in time backups.

```auto
incus storage volume snapshot create default get-my-data my-snapshot

```

To see what snapshots you have on a custom volume:

```auto
incus storage volume info default get-my-data

```

![image](https://discussion.scottibyte.com/uploads/default/original/2X/7/7a49a57ceaca5fb7da56af08215a8cd846518ea2.png)

Let’s create a second snapshot on the volume.

```auto
incus storage volume snapshot create default get-my-data my-snapshot-2

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/5/545fab49518dfff70d1a4cade42b20e3751e216d.jpeg)

Keep in mind that volume snapshots store their data inside of the volume just like container snapshots store their data inside of the container thus making the volume or container much larger.

You can delete a snapshot with the command:

```auto
incus storage volume snapshot delete default get-my-data my-snapshot

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/b/b94c0b7537cf1576732775807173cd72f0f1d7b8.png)

If we want to delete a custom volume that is being used, you must first either delete or disassociate any containers from the volume.

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/7/71d99454afbbe60600da0e8bc98e4a4f36f25de9.jpeg)

If I try to delete the custom volume:

```auto
incus storage volume delete default get-my-data

```

I get an error because although get-my-data is stopped, it is still associated with the container.

![image](https://discussion.scottibyte.com/uploads/default/original/2X/b/b95ed8ec8d529d7335a5dd2bcf82b66a426dbfe6.png)

I can either delete the container or detach it from the volume.

```auto
incus storage volume detach default get-my-data

```

In my example, I deleted the get-my-db container and then I deleted the custom volume.

 ![image](https://discussion.scottibyte.com/uploads/default/original/2X/b/b1bec8895813e190af78da7a3e7f6b12c6b34f7b.jpeg)

Incus custom volumes might be a better way to manage persistent data for Incus docker OCI containers as opposed to persistent folder mappings to the incus server as shown in my last video.
