[英]docker volume create - set permissions
I'm running this on debian 9 我在Debian 9上运行
I'm using sudo docker volume create db
to create a volume I'm using in my docker-compose.yml
. 我正在使用sudo docker volume create db
创建我在docker-compose.yml
使用的卷。 But I still get the error db_1_d89b59353579 | mkdir: cannot create directory '/var/lib/mysql': Permission denied
但是我仍然收到错误db_1_d89b59353579 | mkdir: cannot create directory '/var/lib/mysql': Permission denied
db_1_d89b59353579 | mkdir: cannot create directory '/var/lib/mysql': Permission denied
. db_1_d89b59353579 | mkdir: cannot create directory '/var/lib/mysql': Permission denied
。
How can I set permissions for the user using that volume. 如何为使用该卷的用户设置权限。 And how to get the user? 以及如何获得用户?
Docker-Compose: 多克尔 - 撰写:
version: '2'
volumes:
nextcloud:
db:
services:
db:
image: mariadb
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: always
volumes:
- db:/var/lib/mysql:z
environment:
- MYSQL_ROOT_PASSWORD=***
- MYSQL_PASSWORD=***
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app:
image: nextcloud
ports:
- 8080:80
links:
- db
volumes:
- nextcloud:/var/www/html
restart: always
I got an install.sh file where I run: 我在其中运行了install.sh文件:
...
sudo docker volume create db
sudo docker-compose build
docker-compose up -d
Try to first change the mounts to local folders and see if that fixes your issue: 尝试首先将安装更改为本地文件夹,然后查看是否可以解决您的问题:
version: '2'
volumes:
nextcloud:
db:
services:
db:
...
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=***
- MYSQL_PASSWORD=***
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app:
...
volumes:
- ./nextcloud:/var/www/html
restart: always
If that does then check that the volumes are correctly removed by docker-compose down
. 如果确实如此,则检查docker-compose down
是否已正确删除卷。 Run docker volume ls
. 运行docker volume ls
。 If they still persist then remove them by hand and rerun your containers with the volumes. 如果它们仍然存在,请手动将其删除,然后重新运行包含该卷的容器。
Regarding the difference between mounting to a volume (db:/var/lib/mysql) and mounting to a host path (./db:/var/lib/mysql) : 关于挂载到卷(db:/ var / lib / mysql)和挂载到主机路径(./db:/var/lib/mysql)之间的区别 :
In the first case it is a volume managed by Docker . 在第一种情况下,它是由Docker管理的卷 。 It is meant for persistence but getting to the files is a bit more tricky. 它是为了持久性而设计的,但是获取文件则比较棘手。 In the second case it is a path on the host and it makes it a lot easier to retrieve persisted files. 在第二种情况下,它是主机上的路径 ,这使得检索持久文件变得容易得多。 I recommend to run "docker-compose config" for both situations and see the difference in how docker-compose internally transforms the statement. 我建议在两种情况下都运行“ docker-compose config”,并查看docker-compose在内部如何转换语句的差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.