docker could not mount the linux destination / - docker

docker run -v /Users/xx/var/temp:/ -it alpine bash
But it tips:
invalid mount config for type bind: invalid specification: destination can't be /
Why the alpine host directory could not mount?

Docker won't permit you to bind a host directory or volume to root (/) inside a container. You'll need to bind it at a subdirectory, e.g:
docker run -v /Users/xx/var/temp:/var/temp -it alpine bash
This would make the directory available at /var/temp inside the container.

Related

How to run a python file which is present outside the docker container

Inside VM I created a docker container, Now there are some python files present outside the container(present in host directory of VM) how can I execute these python files from container anyone help me with this
You should mount the vm directory like this:
docker run -d -it --name your-container-name -v /host/path:/usr/local/bin container:image
Also you must be sure /host/path permissions are propperly set.
Volumes in docker
you can copy or mount the python file inside the docker container then execute the python with CMD.
For ex:
docker run -it -v myfile.py:/tmp/myfile.py python python /tmp/myfile.py
docker run -t -i -v <host_dir>:<container_dir> ubuntu /bin/bash
By this command I'm able to access host directory by inside the container where the directories are mounted and can able to run python file present in host by container

Local volume includes invalid characters

I am trying to mount local directory to docker container. Here is the command that i use:
docker run -itd --rm --name chatbot --mount source="$(pwd)",target=/instagram-dm-webhook-service chatbot:12
Where current working dir is: /home/user/instagram-dm-webhook-service
I get this error:
"/home/user/instagram-dm-webhook-service" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
So if i understand this, having dash character in path is ok. Where could be the problem?
Interestingly adding only this didn't work either, / here "/$(pwd)"
volume: mounts a managed volume into the container.
bind: bind-mounts a directory or file from the host into the container.
for more details on mount types - https://docs.docker.com/engine/reference/commandline/service_create/#add-bind-mounts-or-volumes
So you need to explicitly add the mount type to bind for mounting a directory.
docker run -it --mount type=bind,source="/$(pwd)",target=/root ubuntu:18.04 /bin/bash
root#eda980649055:/# cd /root
root#eda980649055:~# ls
Jenkinsfile.migrate LICENSE.txt README.md pom.xml src target
You need to put a / before $(pwd)
docker run -itd --rm --name chatbot --mount source="/$(pwd)",target=/instagram-dm-webhook-service chatbot:12

How to access a directory in hosts machine from inside a docker container?

I'm using docker version Docker version 1.9.1, build a34a1d5 on ubuntu:14.04. I have created a docker container with a volume option like this docker run -it -p 80:8080 -v host/folder:container/folder ubuntu:14.04 /bin/bash. host/folder has some files that i'm trying to access from container/folder. The files from host/folder isnt available from container/folder.
when you mount a host folder as a volume with -v you must specify absolute paths, so replace host/folder and container/folder with the absolute path.
Something like docker run -it -p 80:8080 -v /home/uday/host/folder:/container/folder ubuntu:14.04 /bin/bash (of course set the correct path to your host/folder directory)

How to run application from docker container from host OS?

I'm using docker container with ubuntu:14.04 and some C++ application that I compiled inside docker container.
Is it possible to run application that is inside container from host OS(in my case Win 7)?
Something like:
docker run <path-to-binary>/mybinary -f 10 -o output.txt
UPDATE:
Yes, it's possible
docker run -it <my-image> <path-to-binary>/mybinary
So ideally I want application inside docker will be just like native applications on Windows host OS.
Also is it possible to specify files and folder in host OS as input arguments to application that docker container can't see?
UPDATE:
I tried to mount shared folder at container start
docker run -v C:\shared_with_VM:/temp my_image
and also
docker run -v "C:\shared_with_VM":/temp my_image
But I get error:
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: Invalid
bind mount spec "C:\\shared_with_VM:/temp": invalid mode: /temp.
See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.
As said here right path format on Windows should be
docker run -v /c/shared_with_VM:/temp my_image
I am not sure if I correctly understand your question...
You can mount folders from your host to the container to make it accessible from within your container:
docker run -v /host/folder:/container/ -it <image> <executable> <arguments>
For example:
docker run -v /tmp:/tmphost -it ubuntu ls -al /tmphost
# or in Windows
docker run -v //c/Users/mrgloom/Desktop/data:/tmphost -it ubuntu ls -al /tmphost
This creates the folder /container/ in your container and links it with /host/folder. You can then bidirectonally read / write files inside these folders. Your binary has to point to the input file, which might be located in /container/input.txt

Mount a Host Directory as a Data Volume in docker?

when i try to mount a host directory as data volume in docker its not mount any directory to docker container(image).
When i run
sudo docker run -t -i --name web -v /home/rponna/src/webapp:/opt/webapp ramnathreddy
it returns container id
7dcc03c397d56514015220a073c9e951478bf84aceb90b880bb93a5716079212
But when i run that container it will not show any files in opt/webapp (its empty).

Resources