我安装了Docker CE,并且在新安装的Ubuntu(18.10)上安装了docker compose。从那以后,我在用docker-compose挂载卷时遇到了一个错误。我确定我使用的docker-compose与以前的笔记本电脑(在Ubuntu 16.04上运行)相同。从主目录装载的卷都为空,并且权限不好。
version: '3.3'
# We define volumes here.
# In this case, we define a volume for the database but it's overkill
# because we used this volume only with one container.
volumes:
db-volume:
# We define containers here
services:
# DB container
db:
# We use the image of mariadb (https://hub.docker.com/_/mariadb/).
# Like we don't precise tag, it's the latest version image which is download.
image: mariadb
# We define environment variable like explained in the documentation of the image.
environment:
- MYSQL_ROOT_PASSWORD=root_password
- MYSQL_DATABASE=${DATABASE_NAME}
- MYSQL_USER=drupal
- MYSQL_PASSWORD=drupal
# We used the volume previously defined.
volumes:
- db-volume:/var/lib/mysql
php-cli:
# Here, we use a Dockerfile and not a Docker Image. The file is Dockerfile-php-cli and is in the same repository
# than the docker-compose.yml
build:
context: .
dockerfile: Dockerfile-php-cli
# Arguments pass to the Dockerfile.
args:
USER_UID: ${USER_UID}
volumes:
# Data of application
- ./:/var/www/html:rw
# Share the local user's npm cache as a Docker volume
- ~/.npm:/home/php/.npm:rw
# Share the local user's SSH keys and configuration (read-only)
- ~/.ssh:/home/php/.ssh:ro
# Share the local user's known_host
- ~/.ssh/known_hosts:/home/php/.ssh/known_hosts:rw
# Share the local user's gitconfig
- ~/.gitconfig:/home/php/.gitconfig
environment:
# We define the PATH and add the bin directory of vendor.
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/www/html/vendor/bin
- MYSQL_DATABASE=${DATABASE_NAME}
- MYSQL_USER=drupal
- MYSQL_PASSWORD=drupal
links:
- db
我尝试将docker-compose更改为使用长语法,但我遇到了这个错误:
来自守护程序的错误响应:OCI运行时创建失败:container_linux.go:348:启动容器进程引起了“ process_linux.go:402:容器初始化引起了\” rootfs_linux.go:58:安装\\“ / home / desbois /将/snap/docker/321/.ssh/known_hosts \\“移至rootfs \\” / var / snap / docker / common / var-lib-docker / aufs / mnt / bfbdb2e84826cc2526e5d8220847465065188188dcdccb2e86aec700303b0f8bf9e \\ docker / common / var-lib-docker / aufs / mnt / bfbdb2e84826cc2526e5d8220847465065188cd57cb2e86aec700303b0f8bf9e / home / php / .ssh / known_hosts \\“导致\\”非目录\\“ \”“:未知:您是否要挂载目录到文件上(反之亦然)?检查指定的主机路径是否存在并且是预期的类型
实际上,文件.ssh / known_hosts是容器php-cli上的目录。
我不明白发生了什么事。