docker无法映射(挂载)根目录下的文件夹只能映射家目录
最近想要使用nas-tools做做刮削,电影存在一个机械磁盘里,机械磁盘被挂载到/data1下,发现一个很奇怪的问题,docker只能挂载成功home目录下的文件夹,/data1
,/tmp
这种就挂载不了,比如:
services:
nas-tools:
image: hsuyelin/nas-tools:latest
ports:
- 3000:3000
volumes:
- /home/admin//docker-compose/nas-tools:/config
- /home/admin/video:/video
environment:
- user=root
- UMASK=000
这样设置,就能在nas-tools里看到文件,但是
services:
nas-tools:
image: hsuyelin/nas-tools:latest
ports:
- 3000:3000
volumes:
- /home/admin/docker-compose/nas-tools:/config
- /data1/video:/video
environment:
- user=root
- UMASK=000
这样就不行,后面发现这是因为我在装Ubuntu的时候预装了docker,这个docker是snap docker,他被限制了只能访问/home目录下的文件!
This build can only access files in the home directory. So Dockerfiles and all other files used in commands like docker build, docker save and docker load need to be in $HOME.
---------------------------------------
ref:https://snapcraft.io/docker
解决方法:
-
卸载snap docker
sudo snap remove --purge docker
-
使用apt重新安装docker
Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.ascAdd the repository to Apt sources:
echo
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu
(. /etc/os-release && echo "VERSION_CODENAME") stable" |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get updatesudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world
屏幕中出现了docker的hello world表示安装成功