From c712729d6a582b5c190fe2974829f8f3f0b66cbd Mon Sep 17 00:00:00 2001 From: lucaCambi77 Date: Tue, 16 Aug 2022 03:09:12 +0200 Subject: [PATCH] [ BAEL 5508 ] - Mounting Multiple Volumes on a Docker Container (#12589) * multiple mounts docker compose * exclude localstack files --- .gitignore | 5 ++++- .../multiple-mounts/bind_mount_and_volume.yml | 15 +++++++++++++++ .../docker-compose/multiple-mounts/init.sql | 9 +++++++++ .../multiple-mounts/multiple_bind_mounts.yml | 15 +++++++++++++++ .../multiple-mounts/multiple_volumes.yaml | 15 +++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 docker-modules/docker-compose/multiple-mounts/bind_mount_and_volume.yml create mode 100644 docker-modules/docker-compose/multiple-mounts/init.sql create mode 100644 docker-modules/docker-compose/multiple-mounts/multiple_bind_mounts.yml create mode 100644 docker-modules/docker-compose/multiple-mounts/multiple_volumes.yaml diff --git a/.gitignore b/.gitignore index 48b52bec06..aeb63f7323 100644 --- a/.gitignore +++ b/.gitignore @@ -99,4 +99,7 @@ spring-boot-modules/spring-boot-react/frontend/yarn.lock spring-boot-modules/spring-boot-properties-3/*.log # SDKMan -.sdkmanrc \ No newline at end of file +.sdkmanrc + +# Localstack +**/.localstack \ No newline at end of file diff --git a/docker-modules/docker-compose/multiple-mounts/bind_mount_and_volume.yml b/docker-modules/docker-compose/multiple-mounts/bind_mount_and_volume.yml new file mode 100644 index 0000000000..1a8ea2dc25 --- /dev/null +++ b/docker-modules/docker-compose/multiple-mounts/bind_mount_and_volume.yml @@ -0,0 +1,15 @@ +services: + mysql-db: + image: mysql:latest + environment: + - MYSQL_ROOT_PASSWORD=password + - MYSQL_ROOT_HOST=localhost + ports: + - '3306:3306' + volumes: + - first-volume-data:/var/lib/mysql + - ./init.sql:/docker-entrypoint-initdb.d/init.sql + +volumes: + first-volume-data: + external: true \ No newline at end of file diff --git a/docker-modules/docker-compose/multiple-mounts/init.sql b/docker-modules/docker-compose/multiple-mounts/init.sql new file mode 100644 index 0000000000..345a9914fb --- /dev/null +++ b/docker-modules/docker-compose/multiple-mounts/init.sql @@ -0,0 +1,9 @@ +CREATE DATABASE IF NOT EXISTS test; + +use test; + +CREATE TABLE IF NOT EXISTS test_table (id int, description varchar(255)); + +INSERT INTO test_table VALUES (1, 'TEST_1'); +INSERT INTO test_table VALUES (2, 'TEST_2'); +INSERT INTO test_table VALUES (3, 'TEST_3'); \ No newline at end of file diff --git a/docker-modules/docker-compose/multiple-mounts/multiple_bind_mounts.yml b/docker-modules/docker-compose/multiple-mounts/multiple_bind_mounts.yml new file mode 100644 index 0000000000..98c0275583 --- /dev/null +++ b/docker-modules/docker-compose/multiple-mounts/multiple_bind_mounts.yml @@ -0,0 +1,15 @@ +services: + localstack: + privileged: true + image: localstack/localstack:latest + container_name: localstack + ports: + - '4563-4599:4563-4599' + - '8055:8080' + environment: + - SERVICES=s3 + - DEBUG=1 + - DATA_DIR=/tmp/localstack/data + volumes: + - './.localstack:/var/lib/localstack' + - '/var/run/docker.sock:/var/run/docker.sock' \ No newline at end of file diff --git a/docker-modules/docker-compose/multiple-mounts/multiple_volumes.yaml b/docker-modules/docker-compose/multiple-mounts/multiple_volumes.yaml new file mode 100644 index 0000000000..bd722ac5b5 --- /dev/null +++ b/docker-modules/docker-compose/multiple-mounts/multiple_volumes.yaml @@ -0,0 +1,15 @@ +services: + my_app: + image: web-app:latest + container_name: web-app + ports: + - "8080:8080" + volumes: + - first-volume-data:/container-path-1 + - second-volume-data:/container-path-2:ro + +volumes: + first-volume-data: + driver: local + second-volume-data: + driver: local \ No newline at end of file