Docker Nginx Mount“你是否试图将一个目录挂载到一个文件上(反之亦然)?”

我一直在试图为我的docker做一个备份系统,一切工作正常的数据库容器,除了在Nginx下运行的网络服务器。 我一直在环顾四周,似乎我不是唯一有这个问题的人,但我一直没能找到解决办法。

脚步:

# docker load -i /path/to/backup-image.tar # docker run \ > -v $(pwd)/volumes/home/project/project-git-repo/project-docker/volumes/php-conf/custom-php.ini:/usr/local/etc/php/conf.d/custom-php.ini \ > -v $(pwd)/volumes/home/project/project-git-repo/project-docker/volumes/php-conf/opcache-recommended.ini:/usr/local/etc/php/conf.d/opcache-recommended.ini \ > -v $(pwd)/volumes/home/project/project-git-repo/project-docker/volumes/wp-content:/var/www/html \ > -v $(pwd)/volumes/tmp/html/.well-known:/var/www/html/.well-known \ > --name websrv project_backup_tmp 

这最后的命令输出:

  container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/tmp/project_restore/docker/7aa016ba40e9/volumes/home/project/project-git-repo/project-docker/volumes/php-conf/custom-php.ini\\\" to rootfs \\\"/var/lib/docker/aufs/mnt/b23066c3007d106ae9364ca4e2603e4d5a3e63a0f47d2669ca6580be735adb06\\\" at \\\"/var/lib/docker/aufs/mnt/b23066c3007d106ae9364ca4e2603e4d5a3e63a0f47d2669ca6580be735adb06/usr/local/etc/php/conf.d/custom-php.ini\\\" caused \\\"not a directory\\\"\"" docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/tmp/project_restore/docker/7aa016ba40e9/volumes/home/project/project-git-repo/project-docker/volumes/php-conf/custom-php.ini\\\" to rootfs \\\"/var/lib/docker/aufs/mnt/b23066c3007d106ae9364ca4e2603e4d5a3e63a0f47d2669ca6580be735adb06\\\" at \\\"/var/lib/docker/aufs/mnt/b23066c3007d106ae9364ca4e2603e4d5a3e63a0f47d2669ca6580be735adb06/usr/local/etc/php/conf.d/custom-php.ini\\\" caused \\\"not a directory\\\"\"" : Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type. ERRO[0001] error waiting for container: context canceled 

这是我的docker info的结果:

 Containers: 14 Running: 1 Paused: 0 Stopped: 13 Images: 79 Server Version: 17.06.0-ce Storage Driver: aufs Root Dir: /var/lib/docker/aufs Backing Filesystem: extfs Dirs: 184 Dirperm1 Supported: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4 init version: 949e6fa Security Options: apparmor seccomp Profile: default Kernel Version: 4.4.0-83-generic Operating System: Ubuntu 16.04.2 LTS OSType: linux Architecture: x86_64 CPUs: 8 Total Memory: 19.59GiB Name: rajiska-server ID: 4YFX:52ZF:QKGV:IMY4:6PP4:6P33:JXGT:QHJW:MZTI:QVVX:YU77:ZGR6 Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false WARNING: No swap limit support 

    我遇到了同样的问题,通常是关于将主机上的文件挂载到在另一台机器或虚拟机上运行的容器。

    因此,如果您正在运行的容器位于VirtualBox虚拟机或除本地以外的其他计算机上,则必须找到另一种同步目录的方法。

    但是,如果您使用docker-machine来设置您的VirtualBox虚拟机,它通常会将您的/home目录挂载到创建的虚拟机上的/hosthome

    例如,如果您的项目位于您的主目录中,则可以像这样安装它:

     docker run -v /hosthome/USERNAME/PROJECT:/path/on/container imagename 

    哪里:

    • USERNAME是您在主机上的用户名
    • PROJECT是主机上项目目录的名称