> For the complete documentation index, see [llms.txt](https://docs.glesys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.glesys.com/products/storage/file-storage/how-tos/clients-and-tooling/getting-started-with-docker-and-glesys-file-storage.md).

# Getting started with Docker and Glesys File Storage

***

Glesys's File Storage is a reliable and straightforward solution for storing persistent data in Docker. Because Docker volumes can easily use NFS when it’s installed on the Docker worker, you’re up and running in no time.

## Preparation

Start by creating a virtual machine in Glesys Cloud and granting it access to the file storage. It’s essential that your virtual machine—where your Docker containers will run—can reach the storage volume. You don’t need to mount the file system on the server.

## Installing the necessary packages

We assume that you are using Debian here.

Start by installing the package for NFS:

{% code title="Command" %}

```
sudo apt install nfs-common
```

{% endcode %}

### Installing Docker

Next, you'll need to install Docker. To get the latest version, it's better to install Docker directly from Docker's own repository.

Run the following commands to add Docker's repository to your virtual machine:

{% code title="Multiple commands" %}

```
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
```

{% endcode %}

Then, copy and paste this long command:

{% code title="Command" %}

```
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
```

{% endcode %}

Finally, install Docker by running:

{% code title="Multiple commands" %}

```
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

{% endcode %}

## Trying out an NFS volume in Docker

Create the volume. `NfsVolume1` in the example is the volume's name. Also, replace `fs-vdwx4.cloud.glesys.net` with the URL to your File Storage instance.

{% code title="Command" %}

```
sudo docker volume create --driver local \
    --opt type=nfs \
    --opt o=addr=fs-vdwx4.cloud.glesys.net,rw,vers=4.2 \
    --opt device=:/dpool/nfs \
    NfsVolume1
```

{% endcode %}

Start a Docker container that utilizes the volume. The container is a simple Bash shell:

{% code title="Command" %}

```
sudo docker run -it -v NfsVolume1:/mnt/nfs bash
```

{% endcode %}

Now, while you're still running the container, create a file with some content:

{% code title="Multiple commands (inside container)" %}

```
cd /mnt/nfs
echo "Hello world" > myfile.txt
```

{% endcode %}

Exit the container:

{% code title="Command (inside container)" %}

```
exit
```

{% endcode %}

Let's re-run the container:

{% code title="Command" %}

```
sudo docker run -it -v NfsVolume1:/mnt/nfs bash
```

{% endcode %}

And check out the file you created earlier:

{% code title="Command (inside container)" %}

```
cat /mnt/nfs/myfile.txt
```

{% endcode %}

The output should be:

{% code title="Output" %}

```
Hello world
```

{% endcode %}

Exit the container again with `exit`.

## Using NFS volumes in Docker Compose

Create the following `docker-compose.yml` file. Remember to replace `fs-vdwx4.cloud.glesys.net` with the URL to your File Storage instance. And set a real password for `MYSQL_ROOT_PASSWORD`.

{% code title="docker-compose.yml" %}

```
volumes:
  mysql_data:
    driver: local
    driver_opts:
      type: nfs
      o: addr=fs-vdwx4.cloud.glesys.net,rw,vers=4.2
      device: ":/dpool/nfs/mysql-data"
services:
  mysql:
    image : mysql
    environment:
      MYSQL_ROOT_PASSWORD: super-secret-password
    volumes:
      - type: volume
        source: mysql_data
        target: /var/lib/mysql
```

{% endcode %}

Before we can start this compose project, we need to create the mysql-data directory in our File Storage. The easiest way to do this is to mount it on the server and create the directory (replace `fs-vdwx4.cloud.glesys.net` with the URL to your File Storage):

{% code title="Multiple commands" %}

```
sudo mount -t nfs fs-vdwx4.cloud.glesys.net:/dpool/nfs /mnt
sudo mkdir /mnt/mysql-data
sudo umount /mnt
```

{% endcode %}

Now, you can bring up the Docker Compose project with MySQL:

{% code title="Command" %}

```
sudo docker compose up -d
```

{% endcode %}

Check out its log to make sure everything is working:

{% code title="Command" %}

```
sudo docker compose logs
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.glesys.com/products/storage/file-storage/how-tos/clients-and-tooling/getting-started-with-docker-and-glesys-file-storage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
