Configuring a Container Repository
When running API Gateway and external Elasticsearch as Docker containers, you need to configure volume mapping for external Elasticsearch to properly handle backups.
To configure a container repository
1. Define volume mapping in Docker.
a. Set the backup location as an environment variable. Use the path.repo environment variable to define the backup location inside the external Elasticsearch container.
b. Apply Volume Mapping. Use Docker's volume mapping to link a host directory or named volume to the external Elasticsearch container's backup directory.
A sample Docker command to define volume mapping is as follows:
docker run -d \
-e path.repo=/usr/share/elasticsearch/backup \
-v mybckvolume:/usr/share/elasticsearch/backup \
--name elasticsearch \
docker.elastic.co/elasticsearch/elasticsearch:8.2.3
In this command:
-e path.repo=/usr/share/elasticsearch/backup: Sets the
path.repo environment variable to define the backup location inside the container.
-v mybckvolume:/usr/share/elasticsearch/backup: Maps the named volume
mybckvolume to the container's
/usr/share/elasticsearch/backup directory.
--name elasticsearch: Names the container
elasticsearch.
docker.elastic.co/elasticsearch/elasticsearch:8.2.3: Specifies the external Elasticsearch Docker image and version.
2. Ensure backup location is writable.
If the backup location is not writable, you must change the ownership of the backup directory within the external Elasticsearch container using the docker exec chown command.
A sample change ownership Docker command is as follows:
docker exec -it elasticsearch chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/backup
In this command:
docker exec -it elasticsearch: Runs a command inside the running external Elasticsearch container interactively.
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/backup: Recursively changes the ownership of the backup directory to the
elasticsearch user.
3. Create a backup repository for containers.
A sample command to create a backup repository is as follows:
curl -si -X POST -H "content-type:application/json" -d '{"type": "fs", "settings": {"compress": "true", "location": "/usr/share/elasticsearch/backup/myrepo"}}' http://es-host:es-port/_snapshot/repo-name
In this example:
Replace
es-host and
es-port with the hostname and port number of your external Elasticsearch instance.
Replace
repo-name with the name you want to give to your backup repository. For example, myrepo.