Docker 如何将额外的绑定装载添加到此配置?

Docker 如何将额外的绑定装载添加到此配置?,docker,docker-compose,dockerfile,Docker,Docker Compose,Dockerfile,传递参数有两种方式,我选择了这一种: sudo docker run-d-e url=http://example.com --名称myBlog-p3001:2368-v“$(pwd)/content”:/var/lib/ghost/content ghost:latest 如何添加额外的命令行,使其同时添加绑定装载到: $(pwd)/testFolder/config.production.json卷上的文件将在这里::/var/lib/ghost/config.production.json

传递参数有两种方式,我选择了这一种:

sudo docker run-d-e url=http://example.com --名称myBlog-p3001:2368-v“$(pwd)/content”:/var/lib/ghost/content ghost:latest

如何添加额外的命令行,使其同时添加绑定装载到:

$(pwd)/testFolder/config.production.json
卷上的文件将在这里:
:/var/lib/ghost/config.production.json

而且主机上的文件还不存在,一旦我装载了容器,它就会被容器创建

这就是我尝试过的:

sudo docker run-d-e url=http://example.com --名称myBlog6-p3006:2376-v“$(pwd)/content6”:/var/lib/ghost/content-v/home/ubuntu/config6:/var/lib/ghost/config.production.json ghost:latest

但我得到了一个错误:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/home/ubuntu/config6\\\" to rootfs \\\"/var/lib/docker/overlay2/f8c4ed9231552e91caaeb4f0b8fb9f02108f838e94b659bf049a2df365cd26ef/merged\\\" at \\\"/var/lib/docker/overlay2/f8c4ed9231552e91caaeb4f0b8fb9f02108f838e94b659bf049a2df365cd26ef/merged/var/lib/ghost/config.production.json\\\" caused \\\"not a directory\\\"\"": unknown: 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.

谢谢

如果我没弄错的话,您会得到这个错误,因为您正试图将目录
/home/ubuntu/config6
装载到一个文件
…config.production.json

如果您说将创建文件
config.production.json
,并且在初始化容器后在运行时写入其内容,那么您可以尝试创建一个空文件

touch /home/ubuntu/config6/config.production.json
sudo chmod 777 /home/ubuntu/config6/config.production.json
然后将文件装载到容器中

sudo docker run -d \
  -e url=http://example.com \
  --name myBlog6 -p 3006:2376 \
  -v "$(pwd)/content6":/var/lib/ghost/content \
  -v /home/ubuntu/config6/config.production.json:/var/lib/ghost/config.production.json \
  ghost:latest
在容器将内容写入文件后,您将能够看到它并在下次加载到容器中


chmod
命令用于确保在容器内运行的应用程序具有写入此文件的权限。

我尝试了
sudo docker run-d-e url=http://example.com --名称myBlog-p3001:2368-v“$(pwd)/content”:/var/lib/ghost/content-v/var/www/myBlog/config.production.json:/var/lib/ghost/config.production.json ghost:latest
,它给了我同样的错误。它认为我在用文件绑定文件夹