I am trying to Dockerize and Open Source a project I created in second year of college, this project uses MariaDB, phpMyAdmin and PHP/Yii Framework.
My objective is to make it ready to go using only a simple
docker-compose up
command.
I managed to get the connection between phpMyAdmin and the DB working and now I am stuck on trying to get Docker to have a relative path to a database volume, to make it consistent.
Here is what I have regarding the volume mounting:
volumes:
- './database/mysql/:/var/lib/mysql'
This is storing the database files inside the project and then I can ignore those files in .gitignore
The problem is when I run docker-compose up
with this configuration I get:
Invalid volume specification: 'C:\Users\MySelf\coding\my_app\database\mysql:/var/lib/mysql:rw'
Regarding the host, I am using a Windows with Docker Toolbox but I want the docker-compose.yml
to work regardless of the OS.
I have seen other questions similar but their error came from problems with absolute paths on Windows which I am not looking for.
EDIT: Adding the correct final docker-compose.yml, hopefully it can help
version: '2'
services:
web_db:
build: ./database/mysql
command: "mysqld --innodb-buffer-pool-size=20M"
volumes:
- ./database/mysql/data/:/var/lib/mysql
- ./database/mysql/initDB/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql
environment:
MYSQL_ROOT_PASSWORD: 'YOURPASSWORD'
MYSQL_DATABASE: 'support-technique'
MYSQL_ROOT_HOST: '172.17.0.1'
ports:
- "3306:3306"
container_name: web_db
web:
build: .
depends_on:
- web_db
links:
- web_db:db
ports:
- "80:80"
phpmyadmin:
image: phpmyadmin/phpmyadmin
depends_on:
- web_db
links:
- web_db:mysql
ports:
- "8181:80"
environment:
PMA_HOST: mysql
Where are stored docker volumes Windows? Volumes are stored in a part of the host filesystem which is managed by Docker ( /var/lib/docker/volumes/ on Linux).
Execute the following to connect to MariaDB using the command-line client: > docker exec -it mdb mariadb --user root -pPassword123! And that's it! That's all you need to connect to and start using (querying) MariaDB.
When you Mount a host directory as a data volume, the documentation says:
The
host-dir
can either be an absolute path or a name value. If you supply an absolute path for thehost-dir
, Docker bind-mounts to the path you specify. If you supply a name, Docker creates a named volume by that name.A name value must start with an alphanumeric character, followed by
a-z0-9
,_
(underscore),.
(period) or-
(hyphen).
An absolute path starts with a/
(forward slash).
That explain the error message.
Using an absolute path links it to the OS (which is not what you want)
docker run -v c:\<path>:/c:\<container path>
docker run -v /c/<path>:/c:\<container path>
As mentioned in "Running a docker-compose “Getting Started” example causes “Invalid volume specification” on Windows", try first setting this docker-compose environment variable:
Create
.env
file in the path docker-compose.yml is placed with following content:
COMPOSE_CONVERT_WINDOWS_PATHS=1
The OP Daniel confirms in the comments that with the .env
including COMPOSE_CONVERT_WINDOWS_PATHS
, a relative path works.
I would recommend using a data volume name instead: it won't depend on an host pathname.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With