Installation

Local Volume Mounts for Docker Compose on Ubuntu Server

This article explains how to set up local volume mounts for Docker Compose on an Ubuntu Server. You’ll create required directories, set permissions, update Docker Compose files, and deploy containers.

The following local paths are used for volume mounts:

  • /opt/docker_volumes/temp
  • /opt/docker_volumes/third_party_jars
  • /opt/docker_volumes/files
  • /opt/docker_volumes/es_data

These directories will be mapped to specific paths inside Docker containers for smooth data access and persistence.

Step 1: Create Required Directories

First, create the directories needed for Docker volumes on your Ubuntu server:

$ mkdir /opt/docker_volumes/temp

$ mkdir /opt/docker_volumes/third_party_jars

$ mkdir /opt/docker_volumes/files

$ mkdir /opt/docker_volumes/es_data

Set the correct ownership and permissions:

$ sudo chown -R $USER:$USER /opt/docker_volumes/temp

$ sudo chown -R $USER:$USER /opt/docker_volumes/third_party_jars

$ sudo chown -R $USER:$USER /opt/docker_volumes/files

$ sudo chown -R $USER:$USER /opt/docker_volumes/es_data

$ sudo chmod -R 755 /opt/docker_volumes/*

Step 2: Update the Docker Compose Files

Stop running containers before modifying Docker Compose files:

$ sudo docker-compose -f docker-compose-elasticsearch.yaml down

$ sudo docker-compose down

Edit docker-compose.yaml to add volume mounts:

volumes:

  - /opt/docker_volumes/temp:/home/ovaledge/temp

  - /opt/docker_volumes/third_party_jars:/home/ovaledge/third_party_jars

  - /opt/docker_volumes/files:/home/ovaledge/files

Edit docker-compose-elasticsearch.yaml to mount the Elasticsearch data volume:

volumes:

  - /opt/docker_volumes/es_data:/usr/share/elasticsearch/data

Step 3: Download the Required JAR Files

Download the JAR files into the local volume directory:

$ cd /opt/docker_volumes/third_party_jars

$ wget <jar link>

Step 4: Deploy the Containers

Start the containers using the updated Docker Compose files:

$ sudo docker-compose -f docker-compose-elasticsearch.yaml up -d

$ sudo docker-compose --env-file mysql.env up -d

Conclusion

By following these steps, you have successfully configured local volume mounts for your Docker Compose setup on an Ubuntu server. These mounts ensure persistent storage for temp files, third-party JARs, application files, and Elasticsearch data.