Create folder outside the container in the host machine - spring

I want to change the folder to which the config-server downloads files from git.
when I do it locally in windows, it works perfectly fine, and I can find the created folder.
but when I deploy the config-server to docker, I can't find the folder in the path I chose
this is my properties config
cloud:
config:
server:
git:
uri: "https://bitbucket.org/xxx/remote-config.git"
username: "xxx"
password: "xxx"
basedir: "${CONFIG_LOCAL_REPO_DIR}"
default-label: "master"
clone-on-start: true
force-pull: true
and this is my docker-compose file
version: '3.8'
services:
config-server:
image: "config-server:1.0"
build: "./config-server"
container_name: "config_server"
restart: "always"
networks:
- "network"
volumes:
- "myvolume"
depends_on:
- "rabbitmq"
environment:
CONFIG_LOCAL_REPO_DIR: "myvolume:/home/debian/backend-app/local-repo"
volumes:
myvolume:
networks:
network:
how can I solve this to create in my machine the folder I have chosen?

If you want the data to easily accessible on the host system, i.e. in the same dir as the compose file, use a bind mount.
services:
config-server:
volumes:
- ./local-repo:/myrepo
environment:
CONFIG_LOCAL_REPO_DIR: /myrepo
Note, this is not referencing a volume from the volumes: key in the YAML file, but a path on the host system. In this case, relative to the compose file.

Related

How to Read/Write file system in docker(Winodws)

I'm trying to deploy my java Spring boot application into windows docker container(wsl support is enabled)
When i tried running my yml file the java server is up and running.
But I've a functionality where i need to access the files From Local Disk C & D (host machine)
When ever I tried to access a file with path like "D:\Folder\example.pdf" I'm getting File not found exception.
Here is my docker-compose.yml file
version: "3"
services:
java_spring_backend:
image: java_spring_backend:latest
restart: unless-stopped
container_name: java_spring_backend
build: ./server/
ports:
- "8081:8080"
You must mount the host folder to your docker container.
ex.
version: "3"
services:
java_spring_backend:
image: java_spring_backend:latest
restart: unless-stopped
container_name: java_spring_backend
build: ./server/
volumes:
- "./Folder:/FolderInsideDocker"
Or as absolut path ex. for wsl: /mnt/c/Folder:/FolderInsideDocker
Link to Documentation

Data isn't persisted in the database when using MongoDB with Docker volumes?

There is a service that uses mongodb. But when I restart computer or docker machine, no data is stored in the database.
docker-compose.yml:
version: "3"
Services:
...
mongodb:
restart: always
image: mongo:latest
environment:
- MONGO_DATA_DIR=/dockerdata/db
volumes:
- ./dockerdata/db:/data/db
ports:
- 27017:27017
command: mongod
I tried to do database storage on the host, but it didn't help either:
docker-compose.yml:
version: "3"
Services:
...
mongodb:
restart: always
image: mongo:latest
environment:
- MONGO_DATA_DIR=/c/users/frol/mongodata/db
volumes:
- /c/users/frol/mongodata/db:/data/db
ports:
- 27017:27017
command: mongod
If you make a named volume, docker writes an error:
ERROR: for test_mongodb_1 Cannot create container for service mongodb: fa
To mount local volume: mount /c/users/frol/mongodata/db:/mnt/sda1/var/lib/d
ocker/volumes/test_mongodata/_data, flags: 0x1000: no such file or directory
docker-compose.yml:
version: "3"
services:
...
mongodb:
restart: always
image: mongo:latest
environment:
- MONGO_DATA_DIR=/c/users/frol/mongodata/db
volumes:
- mongodata:/data/db
ports:
- 27017:27017
command: mongod
volumes:
mongodata:
driver: local
driver_opts:
type: none
device: /c/users/frol/mongodata/db
o: bind
Host - win 8.1, docker toolbox 19.03.1 installed.
Help me, please, I'm a novice. How do I make sure that the database data isn't lost?
You first attempt would work if you just fix a simple typo in your compose file:
version: "3"
services:
...
mongodb:
restart: always
image: mongo:latest
environment:
- MONGO_DATA_DIR=/data/db # changed
volumes:
- ./dockerdata/db:/data/db
ports:
- 27017:27017
command: mongod
But, since /data/db is the default value of MONGO_DATA_DIR, setting it is pretty redundant.
But I'd prefer to use a named volume, that way the data persists but I don't have to see the "ugly" database storage folder:
version: "3"
services:
...
mongodb:
restart: always
image: mongo:latest
volumes:
- mongodata:/data/db
ports:
- 27017:27017
command: mongod
volumes:
mongodata:
Don't set $MONGO_DATA_DIR; leave it at its default of /data/db.
services:
mongodb:
restart: always
image: mongo:latest
# No need to specifically set $MONGO_DATA_DIR
volumes:
- ./dockerdata/db:/data/db
ports:
- 27017:27017
# No need to override command:
Docker containers have a separate filesystem space from the host filesystem. A typical setup for most databases is to have the database storage in a fixed location inside the container; for MongoDB that's the /data/db directory. You can mount a named volume or filesystem path there, but the code inside the container doesn't know the difference.
If you do set environment variables like $MONGO_DATA_DIR, they need to reflect paths inside the container; they can't directly specify host-system paths. (#ruohola's answer works because it changes the container-filesystem path of the bind mount to match the container-filesystem path in the environment variable; the host ./dockerdata and container /dockerdata paths are totally unrelated.)
As you are defining the data dir explicitly, you need to map the same directory in the volume to persist the data
version: "3"
services:
...
mongodb:
restart: always
image: mongo:latest
environment:
- MONGO_DATA_DIR=/data/db #data directory
volumes:
- ./dockerdata/db:/data/db #same data directory which you defined above
ports:
- 27017:27017
command: mongod

Volume name issue with docker-compose on windows

I'm trying to start a multi containers applications for codeceptjs using docker-compose. On linux the docker compose yml file works fine but on windows it fails complaining about "volume name is too short". Why docker compose complains on Windows ?
Here's the yml file content:
version: '3.7'
services:
hub:
image: selenium/hub:latest
[...]
chrome:
image: selenium/node-chrome:latest
volumes:
- /dev/shm:/dev/shm
environment:
[...]
networks:
test_network:
ipv4_address: 10.2.0.3
test-acceptance:
image: test/codeceptjs
[...]
volumes:
- $WORKSPACE:/tests
- node_modules:/node_modules
networks:
test_network:
ipv4_address: 10.2.0.5
volumes:
node_modules:
networks:
test_network:
driver: bridge
ipam:
driver: default
config:
-
subnet: 10.2.0.0/24
X
Maybe it's just a typo but the offending values are probably here:
volumes:
node_modules:
You need to put something after the colon.

Laravel specify different name from `.env` or make ingore `.env` in order not to conflict with docker and docker-compose

Because I use docker and docker-compose instead of Homestead and any Vargrant-based solution for development, I want to avoid conflict with laravel on the use of .env file. Therefore, I want for the laravel not to look for this file, instead fetch the required settings data from environmental variables.
So how I can specify, configure the laravel NOT to look for .env file? If that is not possible how I can change the name of the file to search for environmental variables and settings?
The docker-compose.yml is located on the project's root folder.
My docker-compose.yml is the:
version: '3.1'
services:
develop:
image: ddesyllas/php-dev:${TAG}
volumes:
- ".:/var/www/html"
links:
- memcache
environment:
DB_CONNECTION: postgresql
DB_HOST : postgresql
DB_PORT : 5432
DB_DATABASE: ${DOCKER_POSTGRES_DB}
DB_USERNAME: ${DOCKER_POSTGRES_USER}
DB_PASSWORD: ${DOCKER_POSTGRES_PASSWORD}
nginx:
image: nginx:alpine
ports:
- 7880:7880
links:
- "develop:develop"
volumes:
- ".:/var/www/html"
- "./docker/nginx.conf:/etc/nginx/nginx.conf:ro"
postgresql:
image: postgres:alpine
volumes:
- './docker/misc_volumes/postgresql:/var/lib/postgresql/data'
environment:
POSTGRES_USER: ${DOCKER_POSTGRES_USER}
POSTGRES_DB: ${DOCKER_POSTGRES_DB}
POSTGRES_PASSWORD: ${DOCKER_POSTGRES_PASSWORD}
memcache:
image: memcached:alpine
Therefore there's the need for global settings in an aoproach use once-apply globally approach. For example I do not want my laravel application to have access into the ${TAG} enviromental variable at all.
In your docker-compose.yml you can specify the env_file different then .env like:
version: "3.1"
services:
webserver:
image: nginx:alpine
restart: always
container_name: laravel-webserver
working_dir: /application
env_file:
- .env_docker
networks:
- intranet
networks:
intranet:
external: false
Here the docker-compose.yml will use .env_docker instead of .env
Edited:
If you would like to use the different file for the laravel .env then you can change the volumns section to specify that Like:
volumes:
- ".:/var/www/html"
- "./docker/nginx.conf:/etc/nginx/nginx.conf:ro"
- "/<path to your different env file>:/var/www/html/.env"

How can I add a volume for the App_Data folder using docker-compose.override.yml?

I am experimenting with Visual Studio's docker support and want to add a volume mount for C:\inetpub\wwwroot\App_Data.
My Dockerfile looks like this:
FROM microsoft/aspnet:4.7.1-windowsservercore-1709
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
My docker-compose.yml file looks like this:
version: '3.4'
services:
my.app:
image: ${DOCKER_REGISTRY}myapp
build:
context: .\My.App
dockerfile: Dockerfile
Now I've tried just about every variation of specifying volumes in my docker-compose.override.yml file, including:
version: '3.4'
services:
my.app:
volumes:
- "C:\\inetpub\\wwwroot\\App_Data"
ports:
- "80"
networks:
default:
external:
name: nat
services:
my.app:
volumes:
- "C:\\temp\\dockerappdata1":"C:\\inetpub\\wwwroot\\App_Data"
ports:
- "80"
networks:
default:
external:
name: nat
services:
my.app:
volumes:
- type: volume
source: "app_data"
target: "C:\\inetpub\\wwwroot\\App_Data"
ports:
- "80"
networks:
default:
external:
name: nat
volumes:
app_data:
But in all cases, I cannot run the project and it reports either some kind of configuration issue with compose or else an issue when starting the container, with the super-unhelpful message:
encountered an error during Start: failure in a Windows system call: The compute system exited unexpectedly.
What is the right syntax?
version: '3.4'
services:
my.app:
volumes:
- "C:\\inetpub\\wwwroot\\App_Data"
ports:
- "80"
networks:
default:
external:
name: nat
services:
my.app:
volumes:
- "C:\\temp\\dockerappdata1":"C:\\inetpub\\wwwroot\\App_Data"
ports:
- "80"
networks:
default:
external:
name: nat
services:
my.app:
volumes:
- type: volume
source: "app_data"
target: "C:\\inetpub\\wwwroot\\App_Data"
ports:
- "80"
networks:
default:
external:
name: nat
volumes:
app_data:
The problem I think here is, you are trying to mount a directory which is already there.
If I understand your question correctly, you'd like to volume mount "C:\inetpub\wwwroot\App_Data" into the container, correct?
If that's the case, here's what you should add in the yaml file:
services:
my.app:
volumes:
- C:\\inetpub\\wwwroot\\App_Data:C:\\temp\\dockerappdata1
# Syntax is HOST_PATH:CONTAINER_PATH:[ro/rw] (the access mode is optional)
ports:
- "80"
More info on the syntax: https://docs.docker.com/compose/compose-file/#short-syntax-3

Resources