Reputation: 579
On an old server running docker I have a two containers running ipam and mysql. The mysql has mounted a volume and after stopping the containers, I copied the contents of the volume to a new server, into the directory:
/mnt/dockerdata/vols/ipam/phpipam-mysql
Next I create a volume on that new server: docker volume create --driver local --opt device=/mnt/dockerdata/vols/ipam/phpipam-mysql phpipam-mysql --opt type=volume
Next I created a docker-compose.yml file to try and make this repeatable. Not really needed here, but I want to learn for other projects. So I created this file: (I'm aware of the password, but it is just my lab)
services:
ipam-mysql:
container_name: ipamdb
image: mysql:5.6
environment:
- MYSQL_ROOT_PASSWORD=P@55F0rIP@M
restart: always
volumes:
- phpipam-mysql:/var/lib/mysql
ipam:
container_name: ipambase
depends_on:
- ipam-mysql
image: pierrecdn/phpipam
environment:
- MYSQL_ENV_MYSQL_USER=root
- MYSQL_ENV_MYSQL_ROOT_PASSWORD=P@55F0rIP@M
- MYSQL_ENV_MYSQL_HOST=mysql
ports:
- "192.168.0.10:80:80"
volumes:
phpipam-mysql:
external: true
name: phpipam-mysql
But this returns the following errors:
Building with native build. Learn about native build in Compose here: https://docs.docker.com/go/compose-native-build/
Creating ipamdb ... error
ERROR: for ipamdb Cannot create container for service ipam-mysql: failed to mount local volume: mount /mnt/dockerdata/vols/ipam/phpipam-mysql:/var/lib/docker/volumes/phpipam-mysql/_data: no such device
ERROR: for ipam-mysql Cannot create container for service ipam-mysql: failed to mount local volume: mount /mnt/dockerdata/vols/ipam/phpipam-mysql:/var/lib/docker/volumes/phpipam-mysql/_data: no such device
ERROR: Encountered errors while bringing up the project.
When I don't use the external:true
option, a new empty volume is created which I don't want. I tried creating the volume with the type ext4 but that doesn't change the error.
Any tips?
Upvotes: 0
Views: 138
Reputation: 11605
The volume you create is set to mount a device, not a folder, therefore the no such device
error.
To create a volume binded to a folder:
volume create --driver local --opt device=/mnt/dockerdata/vols/ipam/phpipam-mysql phpipam-mysql --opt type=none --opt o=bind
Upvotes: 1