简体   繁体   English

尝试创建已装入卷的容器时出错

[英]Error when trying to create container with mounted volume

I'm trying to mount a volume on a container so that I can access files on the server I'm running the container. 我正在尝试在容器上安装卷,以便可以访问正在运行容器的服务器上的文件。 Using the command 使用命令

docker run -i -t 188b2a20dfbf -v /home/user/shared_files:/data ubuntu /bin/bash

results in the error 导致错误

docker: Error response from daemon: OCI runtime create failed:
container_linux.go:296: starting container process caused "exec: \"-v\": 
executable file not found in $PATH": unknown.

I'm not sure what to do here. 我不确定在这里做什么。 Basically, I need to be able to access a script and some data files from the host server. 基本上,我需要能够从主机服务器访问脚本和一些数据文件。

The docker command line is order sensitive. docker命令行是顺序敏感的。 After the image name, everything passed is a command that runs inside the container. 在映像名称之后,传递的所有内容都是在容器内运行的命令。 For docker, the first thing that doesn't match an expected argument after the run command is assumed to be the image name: 对于docker,将run命令之后与预期参数不匹配的第一件事假定为映像名称:

docker run -i -t 188b2a20dfbf -v /home/user/shared_files:/data ubuntu /bin/bash

That tries to run a -v command inside your image 188b2a20dfbf because -t takes no value. 尝试在图像188b2a20dfbf内部运行-v命令,因为-t没有值。

docker run -i -t  -v /home/user/shared_files:/data 188b2a20dfbf /bin/bash

That would run bash in that same image 188b2a20dfbf. 那将在同一图像188b2a20dfbf中运行bash

If you wanted to run your command inside ubuntu instead (it's not clear from your example which you were trying to do), then remove the 188b2a20dfbf image name from the command: 如果您想在ubuntu中运行命令(从您的示例中并不清楚要执行的操作),请从命令中删除188b2a20dfbf映像名称:

docker run -i -t -v /home/user/shared_files:/data ubuntu /bin/bash

Apparently, on line 296 on your .go script you is referring to something that can't be found. 显然,在.go脚本的第296行中,您引用的是找不到的东西。 Check your environment variables to see if they contain the path to that file, if the file is included in the volume at all, etc. 检查环境变量以查看它们是否包含该文件的路径,该文件是否完全包含在卷中,等等。

188b2a20dfbf passed to -t is not right. 传递给-t 188b2a20dfbf是不正确的。 -t is used to get a pseudo-TTY terminal for the container: -t用于获取容器的伪TTY终端:

$ docker run --help
...
-t, --tty         Allocate a pseudo-TTY

Run docker run -i -t -v /home/user/shared_files:/data ubuntu /bin/bash . 运行docker run -i -t -v /home/user/shared_files:/data ubuntu /bin/bash It works for me: 这个对我有用:

$ echo "test123" > shared_files

$ docker run -i -t -v $(pwd)/shared_files:/data ubuntu /bin/bash
root@4b426995e373:/# cat /data 
test123

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM