简体   繁体   中英

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. 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 -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.

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

That would run bash in that same image 188b2a20dfbf.

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:

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. 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 is used to get a pseudo-TTY terminal for the container:

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

Run 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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