Hi, I am installing a mysql container and I want it to take my datas from my windows host machine.
Here is the compose file I have writed, but it doesnt recognize tha name variable:
version: "3.7"
services:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- type: volume
source: C:\ProgramData\MySQL\MySQL Server 8.0\Data\test1
target: /var/lib/mysql/
name: sqldata
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
sqldata:
Ive also tried
volumes:
- C:\ProgramData\MySQL\MySQL Server 8.0\Data\test1:/var/lib/mysql/
Ive already enabled $Env:COMPOSE_CONVERT_WINDOWS_PATHS=1
to accept window’s format path but I cant make it work
Assuming your goal is for the container(s) to have direct access, don’t use type:volume but type:bind.
Comand line:
docker run -d -it --name dbtest0 --mount type=bind,source="/c/kurowski/matthew/mysql/test",target=/var/lib/mysql lts:mak-mysql
YAML compose file:
version: "3.7"
services:
image: lts:mak-mysql
volumes:
- type: bind
source: /c/kurowski/matthew/mysql/test
target: /var/lib/mysql/
container_name: dbtest0
Hope this helps,
Matthew
Thank you for your help I have opened some docs about bind volumes and that was exactly what I needed for.
However there is not much informations on docker windows, I’ve seen that the path of the source is written as it is on windows
C:\Users\fil1\my file2\myfile_3
but you used
/c/Users/ffil1/my file2/myfile
, which one is the correct format ? and does it allows spaces on the name ?
Yes, if you have spaces in the Windows source, you can encapsulate the value. The format I used works on Docker for Windows. The other format option works as well.
Command line (with space in src directory):
docker run -d -it --name spacetest --mount type=bind,source="/c/kurowski/matthew/mysql test",target=/var/lib/mysql/test lts:mak-mysql
docker run -d -it --name spacetest --mount type=bind,source="c:\kurowski\matthew\mysql test",target=/var/lib/mysql/test lts:mak-mysql
YAML compose:
version: "3.7"
services:
image: lts:mak-mysql
volumes:
- type: bind
source: "c:\kurowski\matthew\mysql test"
target: /var/lib/mysql/
container_name: spacetest
or YAML compose:
version: "3.7"
services:
image: lts:mak-mysql
volumes:
- type: bind
source: "/c/kurowski/matthew/mysql test"
target: /var/lib/mysql/
container_name: spacetest
Cheers,
Matthew
But I get this error:
ERROR: for test/db Cannot create container for service db: Mount denied:
The source path “None”
Creating test/php … error