Cannot mount a folder with Docker - docker

I can't get the -v option to work with Docker. My host is Linux Mint and my image is using Ubuntu:latest.
sudo docker run -it opencv:latest -v /home/rr/Desktop/mytest:/src
It gives the error
docker: Error response from daemon: OCI runtime create failed:
container_linux.go.345: starting container process caused
"exec: \"-v\": executable file not found in $PATH": unknown.
I have tried different things. Both mounting to a folder in the image that exists and one that does not, but it is the same error either way.

The usage of docker run is:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
So your options need to go before the image name, including the -v option. If you put it after the image name, it sees it as the command to run instead of an option. Try:
sudo docker run -it -v /home/rr/Desktop/mytest:/src opencv:latest

Related

How to mount a windows folder in docker container?

On my windows notebook I try to share a folder with my docker container, but I am getting a weird error message that does not tell me anything.
docker run -p 9999:9999 -it msmint/msmint:latest -v c:/Users/swacker/MINT:/data/
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "-v": executable file not found in $PATH: unknown.
The /data folder in the docker file is present and I gried different formats for the windows path such as C:\User\swacker\MINT.
It complains that an executable file is not found, but I don't know which one.
Options for docker need to go before the image name. Anything after the image name is a command for the container and replaces any defined CMD in the image.
So you need to do
docker run -p 9999:9999 -it -v c:\Users\swacker\MINT:/data/ msmint/msmint:latest
I've changed the slashes in your Windows path to backslashes.

`$PATH: unknown` error when mounting the current directory in Docker

I want to use Docker to manage multiple Python versions (I recently got a Mac with Apple Silicon and I use old Python environment).
Since I need to read Python scripts on Docker and save the output files (for later use outside the Docker environment), I tried to mount a folder (on my Mac) following this post.
However, it shows this error:
$ docker run --name dpython -it python-docker -v $(pwd):/tmp /bin/bash
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "-v": executable file not found in $PATH: unknown.
ERRO[0000] error waiting for container: context canceled
It works without -v $(pwd):/tmp. I tried to specify different folders such as ~/ and /Users/ but they didn't work.
You must specify the volume before the image name:
$ docker run --name dpython -it -v $(pwd):/tmp python-docker /bin/bash

Running a container with a Docker bind-mount causes container to return Node version and exit

I am trying to attach a directory of static assets to my docker instance after it has been built. When I do something like this
docker run -it app /bin/bash
The container runs perfectly fine. However, if I do something like this:
docker run -it app -v "${PWD}/assets:/path/to/empty/directory" /bin/bash
This also reproduces it:
docker run -it node:12.18-alpine3.12 -v "${PWD}/assets:/path/to/empty/directory" /bin/bash
It spits out the version of Node v12.18.4 I am using and immediately dies. Where am I going wrong? I am using docker with wsl2 on windows 10. Is it due to filesystem incompatibility?
edit: whoops it's spitting out the node version and not the alpine version
To debug my issue I tried running a bare-bones alpine container:
docker run -it alpine:3.12 -v "${PWD}/assets:/usr/app" /bin/sh
Which gave a slightly more useful error message:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"-v\": executable file not found in $PATH": unknown.
From this I realized that docker was trying to run -v as a starting command. I decided to change the order around, things started working.
TL;DR The -v argument and its corresponding parameter must be placed before the container name when performing a docker run command. i.e. the following works
docker run -it -v "${PWD}/assets:/usr/app" alpine:3.12 /bin/sh
but this doesn't:
docker run -it alpine:3.12 -v "${PWD}/assets:/usr/app" /bin/sh

Cannot run FreeBSD terminal in docker container

I am using a FreeBSD image from dockerhub. After pulling the image, I need to run a container with a terminal to test some commands inside the container.
I am trying this command:
sudo docker run --rm -it auchida/freebsd ./bin/bash
And I get the error:
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:348: starting container process caused "exec:
\"./bin/bash\": stat ./bin/bash: no such file or directory": unknown
Could anyone help me ?
There is no bash binary embedded in the image, located at /bin/bash or everywhere else : you can check it by looking at base.txz contents.
You can use /bin/sh instead (the default shell, take a look at the Dockerfile) :
sudo docker run --rm -it auchida/freebsd /bin/sh
(/bin/sh is optional in the previous command, since it is the default CMD).
If you really want bash, you must install it.
Note also that you must be on a FreeBSD host to be able to run a container with this image.

Docker --mount throws: executable file not found in $PATH"

Running:
docker run 6740371b6542 --mount
docker run 6740371b6542 --mount source=aws,target=/root/.aws/,readonly
both produce the same error:
container_linux.go:265: starting container process caused "exec: \"--mount\": executable file not found in $PATH"
docker: Error response from daemon: oci runtime error: container_linux.go:265: starting container process caused "exec: \"--mount\": executable file not found in $PATH".
Can someone explain how to mount a file/folder from the host into the docker container? It seems --mount is the current/latest recommended way to do it.
switching the order of the parameters should resolve that problem
docker run --mount source=aws,target=/root/.aws/,readonly 6740371b6542
docker run executes a command as its last parameter. the error you received was due to the container not knowing what the --mount command is
In the future if you want to run a command in a container dont forget to use bash if you want to preserve path variables
docker run --mount source=aws,target=/root/.aws/,readonly 6740371b6542 /bin/bash -c mysql

Resources