Docker bind mount directory in /tmp not working - docker

I'm trying to mount a directory in /tmp to a directory in a container, namely /test. To do this, I've run:
docker run --rm -it -v /tmp/tmpl42ydir5/:/test alpine:latest ls /test
I expect to see a few files when I do this, but instead I see nothing at all.
I tried moving the folder into my home directory and running again:
docker run --rm -it -v /home/theolodus/tmpl42ydir5/:/test alpine:latest ls /test
at which point I see the expected output. This makes me thing I have mis-configured something and/or the permissions have bitten me. Have I missed a step in installing docker? I did it via sudo snap install docker, and then configured docker to let me run as non-root by adding myself to the docker group. Running as root doesn't help...
Host machine is Ubuntu 20.04, docker version is 19.03.11

When running docker as a snap...
all files that Docker uses, such as dockerfiles, to be in $HOME.
Ref: https://snapcraft.io/docker
The /tmp filesystem simply isn't accessible to the docker engine when it's running within the snap isolation. You can install docker directly on Ubuntu from the upstream Docker repositories for a more traditional behavior.

Related

docker bind mounting not work with "not home" folder

I'm tring to play with bind mounting and i encourred in a strange behavior, i understand that bind mounting mount a host's folder in the container file system obscuring the original container content. Now when i try to do for examle:
docker run -it -v /home/user:/tmp ubuntu bash
in the /tmp folder of contaner there is the user's home but when i try to bind a "not home folder" like /var/lib:
docker run -it -v /var/lib:/tmp ubuntu bash
the /tmp folder inside a container is empty, why this appen?
Moreover if i do inside at the last container for example "touch foo" and i run another container with the same binding:
docker run -it -v /var/lib:/tmp ubuntu bash
I'll find the foo file inside /tmp folder
additional info: i run a ubuntu 19 server inside a VMaware virtual machine
i found a "dirty" solution, i had previoussly installed docker via snap, i reinstalled docker via apt and now work fine, this will remain a minstery

Volume not mounting properly when running shell inside a container

I want to encrypt my Kubernetes file to integrate it with Travis CI and for that, I am installing Travis CI CLI via docker container. When the container runs and I mount my current working directory to /app It just creates an empty folder.
I have added the folder in shared folders as well in the Virtual Box but nothing seems to work. I am using Docker Toolbox on Windows 10 home.
docker run -it -v ${pwd}:/app ruby:2.3 sh
It creates the empty app folder along with the other folders in the container but does not mount the volumes.
I also tried using
docker run -it -v //c/complex:/app ruby:2.3 sh
as someone suggested to use the name you specify in the Virtual Box.
Docker run -it -v full path of current directory:/app ruby:2

Docker not mapping folders

I am connected in a Docker container. In this container, when I execute:
sudo docker run --entrypoint bash -it -v /home/jenkins/workspace/deployment:/app myregistry.com/ansible-shade:2.2.1.0
I can see mapping is not happening between /home/jenkins/workspace/deployment and /app
In /home/jenkins/workspace/deployment, there is a lot of files, but in /app, I can't see anything
Any idea why does it happen ?
I found out what the problem,
My use case is that I work in a centOS that has all files, then I ssh a ubuntu that has no file and then in this ubuntu, I connect to docker container, so source path is from ubuntu not the docker image ( where files are )
The solution in that case is having files in the ubuntu vm so it can be mounted

How can I make Docker Images / Volumes (Flask, Python) accessible for my host machine (macOS)?

I am running the latest macOS (Sierra) with Docker and Kitematic installed. I am also using Virtualbox for emulation.
I want to use the uwsgi-nginx-flask image but I have no idea how I can make the python files and the nginx directory inside my container accessible from outside the virtual machine ?
Haven't found anything about that on the website either.
Folders between the host and containers can be mapped and mounted by using the -v tag during runtime.
$ docker run -it -v /host/directory:/container/directory imagename:tag
You can alternatively use docker cp to copy stuff inside and outside of the container. For example
$ docker cp /path/to/file ContainerName:/path/inside/container
or
$ docker cp ContainerName:/path/inside/container/file .
you can mount the host directory to docker container which will be shared between host and docker
docker run --name container_image -d -v ~/host_dir:/container_dir docker_image

docker toolbox mount file on windows

I am a beginner with docker and I am using a windows machine. But I have a problem mounting files using volumes. The documentation says the following thing about mount files on OSX and windows :
Official docker docs
Note: If you are using Docker Machine on Mac or Windows, your Docker daemon only has limited access to your OS X/Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory - and so you can mount files or directories using docker run -v /Users/<path>:/<container path> ... (OS X) or docker run -v /c/Users/<path>:/<container path ... (Windows). All other paths come from your virtual machine’s filesystem.
I have a small nginx Dockerfile:
FROM centos:6.6
MAINTAINER afym
ENV WEBPORT 80
RUN yum -y update; yum clean all
RUN yum -y install epel-release; yum clean all
RUN yum -y install nginx; yum clean all
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
VOLUME /usr/share/nginx/html
EXPOSE $WEBPORT
CMD [ "/usr/sbin/nginx" ]
Creating a simple container
docker run -d --name simple -p 8082:80 ng1
8875448c01a4787f1ffe4c4c5c492efb039e452eff957391ac52a08915e18d66
Creating a container with a volume
My windows host directory
Creating the docker container with -v option
docker run -d --name simple2 -v /c/Users/src:/usr/share/nginx/html -p 8082:80 ng1
invalid value "C:\\Users\\src;C:\\Program Files\\Git\\usr\\share\\nginx\\html"
for flag -v: bad mount mode specified
: \Program Files\Git\usr\share\nginx\html
See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.
Inspecting the ng1 image
docker inspect ng1
What is wrong when I am creating a docker container with a volume?
Thanks.
Try to run it with additional / for volume like:
docker run -d --name simple2 -v /c/Users/src://usr/share/nginx/html -p 8082:80 ng1
Or even for host OS, as
docker run -d --name simple2 -v //c/Users/src://usr/share/nginx/html -p 8082:80 ng1
Due to this issue:
This is something that the MSYS environment does to map POSIX paths to Windows paths before passing them to executables.
As the OP said:
Official docker docs :
Note: If you are using Docker Machine on Mac or Windows, your Docker
daemon only has limited access to your OS X/Windows filesystem. Docker
Machine tries to auto-share your /Users (OS X) or C:\Users (Windows)
directory - and so you can mount files or directories using
docker run -v /Users/:/ ... (OS X)
or
docker run -v /c/Users/:/
But if you want access to other directories, you need to add a new shared folder to the virtual box settings (Settings > Shared Folders > Add share).
Add there a new share (only possible when you stop the vm before, docker-machine stop:
path C:\Projects
name c/Projects
autoMount yes
Or edit directly the vbox configuration file
C:\Users\<username>\.docker\machine\machines\default\default\default.vbox
Add there into <SharedFolders> the line
<SharedFolder name="c/Projects" hostPath="\\?\c:\Projects" writable="true" autoMount="true"/>
Restart the machine:
docker-machine stop
docker-machine start
Now, it's possible to mount also directories with the base C:\Projects
docker run -v //c/Projects/myApp://myApp <myImage>
For anyone using docker ~> 1.12 and faces this issue. I spent 30min trying to figure it out until i realized you have to specifically share a drive first via docker settings, see:
https://docs.docker.com/docker-for-windows/#/shared-drives
If you're simply looking to access a local drive, the MINGW32 Docker Toolbox terminal puts the root of each drive in /<drive-letter>, so drive C:\ will be at /c/

Resources