Volume name issue with docker-compose on windows - 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.

Related

docker application not communicate with docker mysql container

I just encountered a problem. I am dockerizing a springboot application with MySQL as a database it is perfectly working in a local setup. But when I try to dockerize the application using docker-compose, MySQL container is working fine and is accessible in my workbench but my application is not able to access it throwing the communication link failure.
This is the compose file I am using:
version: "3.8"
services:
mysqldb:
image: mysql:5.7
restart:unless-stopped
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=baskartest
ports:
- 3307:3306
volumes:
- db:/var/lib/mysql
app:
depends_on:
- mysqldb
build: ./bezkoder-app
restart:on-failure
env_file: ./.env
ports:
- 8084:8080
environment:
SPRING_APPLICATION_JSON: '{
"spring.datasource.url" : "jdbc:mysql://mysqldb:3306/baskartest?useSSL=false",
"spring.datasource.username" : "root",
"spring.datasource.password" : "root",
"spring.jpa.properties.hibernate.dialect" : "org.hibernate.dialect.MySQL5InnoDBDialect",
"spring.jpa.hibernate.ddl-auto" : "update"
}'
volumes:
- .m2:/root/.m2
stdin_open: true
tty: true
MySQL is working fine but my app in services is not able to communicate with it.
Here is what I see:
Any help would be appreciated!
I have done small changes in docker-compose.yml file, please use this one. It is working fine.
version: "3.8"
services:
mysqldb:
image: mysql:5.7
container_name: MYSQL_DB
restart: unless-stopped
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=baskartest
ports:
- 3307:3306
app:
build: ./bezkoder-app
restart: on-failure
ports:
- 8084:8080
environment:
- SPRING_DATASOURCE_URL=jdbc:mysql://MYSQL_DB:3306/baskartest
- SPRING_DATASOURCE_USERNAME=root
- SPRING_DATASOURCE_PASSWORD=root
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
depends_on:
- mysqldb
In my short experience with Docker and containers communicating with eachother, I've found that localhost configuration URL's aren't working. Because one container can't communicatie with another container using just localhost:[PORT].
A lazy way for me to fix this is to work out a static IP address of the machine the containers are running on. Then use this (local) IP address instead of localhost to define the endpoint of the database.
In my situation with Redis I'm doing it like this:
return new LettuceConnectionFactory(new RedisStandaloneConfiguration("192.168.1.201", 6379));
In your situation, you might want to use a Datasource URL like this:
- SPRING_DATASOURCE_URL=jdbc:mysql://[STATIC_IP_OF_MACHINE]:3306/baskartest
*i.e. ...192.168.1.100:3306/baskartest...*

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

Running Sonarqube with docker-compose using bind mount volumes

I’m trying to run Sonarqube in a Docker container on a Centos 7 server using docker-compose. Everything works as expected using named volumes as configured in this docker-compose.yml file:
version: "3"
services:
sonarqube:
image: sonarqube
ports:
- "9000:9000"
networks:
- sonarnet
environment:
- sonar.jdbc.url=jdbc:postgresql://db:5432/sonar
volumes:
- sonarqube_conf:/opt/sonarqube/conf
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_bundled_plugins:/opt/sonarqube/lib/bundled-plugins
db:
image: postgres
networks:
- sonarnet
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data
networks:
sonarnet:
driver: bridge
volumes:
sonarqube_conf:
sonarqube_data:
sonarqube_extensions:
sonarqube_bundled_plugins:
postgresql:
postgresql_data:
However, my /var/lib/docker/volumes directory is not large enough to house the named volumes. So, I changed the docker-compose.yml file to use bind mount volumes as shown below.
version: "3"
services:
sonarqube:
image: sonarqube
ports:
- "9000:9000"
networks:
- sonarnet
environment:
- sonar.jdbc.url=jdbc:postgresql://db:5432/sonar
volumes:
- /data/sonarqube/conf:/opt/sonarqube/conf
- /data/sonarqube/data:/opt/sonarqube/data
- /data/sonarqube/extensions:/opt/sonarqube/extensions
- /data/sonarqube/bundled_plugins:/opt/sonarqube/lib/bundled-plugins
db:
image: postgres
networks:
- sonarnet
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
volumes:
- /data/postgresql:/var/lib/postgresql
- /data/postgresql_data:/var/lib/postgresql/data
networks:
sonarnet:
driver: bridge
However, after running docker-compose up -d, the app starts up but none of the bind mount volumes are written to. As a result, the Sonarqube plugins are not loaded and the sonar postgreSQL database is not initialized. I thought it may be a selinux issue, but I temporarily disabled it with no success. I’m unsure what to look at next.
I think my answer from "How to persist configuration & analytics across container invocations in Sonarqube docker image" would help you as well.
For good measure I have also pasted it in here:
.....
Notice this line SONARQUBE_HOME in the Dockerfile for the docker-sonarqube image. We can control this environment variable.
When using docker run. Simply do:
txt
docker run -d \
...
...
-e SONARQUBE_HOME=/sonarqube-data
-v /PERSISTENT_DISK/sonarqubeVolume:/sonarqube-data
This will make Sonarqube create the conf, data and so forth folders and store data therein. As needed.
Or with Kubernetes. In your deployment YAML file. Do:
txt
...
...
env:
- name: SONARQUBE_HOME
value: /sonarqube-data
...
...
volumeMounts:
- name: app-volume
mountPath: /sonarqube-data
And the name in the volumeMounts property points to a volume in the volumes section of the Kubernetes deployment YAML file.
This again will make Sonarqube use the /sonarqube-data mountPath for creating extenions, conf and so forth folders, then save data therein.
And voila your Sonarqube data is thereby persisted.
I hope this will help others.
N.B. Notice that the YAML and Docker run examples are not exhaustive. They focus on the issue of persisting Sonarqube data.
Try it out BobC and let me know.
Have a great day.
The below code will help you in a single command I hope so.
Create a new docker-compose file named as docker-compose.yaml,
version: "3"
services:
sonarqube:
image: sonarqube:8.2-community
depends_on:
- db
ports:
- "9000:9000"
networks:
- sonarqubenet
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonarqube
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
- sonarqube_temp:/opt/sonarqube/temp
restart: on-failure
container_name: sonarqube
db:
image: postgres
networks:
- sonarqubenet
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data
restart: on-failure
container_name: postgresql
networks:
sonarqubenet:
driver: bridge
volumes:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
sonarqube_temp:
postgresql:
postgresql_data:
Then, execute the command,
$ docker-compose up -d
$ docker container ps
Sounds like the container is running and, as you mentioned, Sonarqube starts-up. When it starts, is it showing that it's using the H2 in memory db? After running docker-compose up -d, use docker logs -f <container_name> to see what's happening on Sonarqube startup.
To simplify viewing your logs with a known name, I suggest you also add a container name to your Sonarqube service. For example, container_name: sonarqube.
Also, while I know the plan is to deprecate the use of environment variables for the username, password and jdbc connection, I've had better luck in docker-compose using environment variables rather than the corresponding property value. For the connection string, try: SONARQUBE_JDBC_URL: jdbc:postgresql://db/sonar without specifying the default port for postgres.

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

How docker volume container (mounted a host directory ) used in compose file version 2

In compose file version 1 , my docker-compose.yml is :
mongo:
image: mongo
volumes_from:
- mongodata
mongodata:
image: mongo
volumes:
- /home/dbdata/mongodb:/data/db
In localhost "/home/dbdata/mongodb" ,i saved some data . And it can be read through mongo container .
But i don't know how to update to compose file version 2. I have updated docker and docker-compose to the latest.
Docker version 1.10.2, build c3959b1
docker-compose version 1.6.2, build 4d72027
OS: ubuntu 15.10
I tried three ways ,but not working.
one : the compose file is :
version: '2'
services:
mongo:
image: mongo
volumes_from:
- mongodata
networks:
- wfij
mongodata:
image: mongo
volumes:
- /home/dbdata/mongodb:/data/db
# this is a spring cloud service , it can read mongo user data
useraccount:
image: user-account
networks:
- wfij
networks:
wfij:
driver: bridge
But the spring user-account service can't read the mongo data .
Another method: the compose file
-
version: '2'
services:
mongo:
image: mongo
volumes:
- mongo-data:/data/db
networks:
- wfij
useraccount:
image: user-account
networks:
- wfij
networks:
wfij:
driver: bridge
volumes:
mongo-data:
volumes: home/dbdata/mongodb
It not works again , the error is : "volumes is not supported" , but if i not set the volume container ,how can i mount the host directory "home/dbdata/mongodb" to the volume .
last , try this :
mongo:
image: mongo
volumes:
- mongo-data
voluems:
- mongo-data: /home/keryhu/dbdata/mongodb:/data/db
The error is :
ERROR: In file './docker-compose.yml', volume 'mongo-data' must be a mapping not a string.
Can help me ?
version: '2'
services:
mongo:
image: mongo
volumes_from:
- mongodata
mongodata:
image: mongo
volumes:
- /home/dbdata/mongodb:/data/db
This should work. You don't have to make any changes for host volumes. It's only important for named volumes.

Resources