Docker volume mapping not working (Linux containers) - docker

Docker 17.09.0-ce-win33 (13620)
Running the command:
docker run --rm -it -v ${PWD}:/api -p 6000:5000 microsoft/dotnet
I should get the content of the current folder in the linux /api folder.
For some reason the mapping folder was created, yet there is not content...
cd api
ls -a
Shows an empty list...
Switching to Windows containers and running
docker run --rm -it -v ${PWD}:c:\API -p 6000:5000 microsoft/dotnet
Also gives me an empty folder...
Ran Powershell as Administrator to no avail.. any thoughts?

Related

Cannot mount volume for drive d:\ or e:\ in Docker Desktop for Windows

Searched internet & stackoverflow for this but no success
Using Docker for Desktop version 4.12.0 on Windows 10 with WSL2 as backend.
In window's command prompt window, following works and lists files in c:/data
docker run --rm -v c:/data:/target alpine ls /target
But none of following works. /target directory is always empty!
docker run --rm -v d:/data:/target alpine ls /target
docker run --rm -v "d:/data:/target" alpine ls /target
docker run --rm -v "d:/data":/target alpine ls /target
docker run --rm -v /mnt/d/data:/target alpine ls /target
docker run --rm -v /run/desktop/host/d/data:/target alpine ls /target
docker run --rm -v "/run/desktop/host/d/data:/target" alpine ls /target
However, within WSL 2 terminal window following works and lists files under /target directory !
docker run --rm -v /mnt/d/data:/target alpine ls /target
But I want to use Docker Desktop for Windows and use windows command prompt. Ultimately want to mount volume inside docker-compose.yml.
Some of above commands seems to have been working for different people based on stackoverflow answers in past. Don't know if it's because of different version of Docker for Desktop or not clear if they were trying in WSL2 terminal window or Windows command prompt window.
TIA
You are facing a Microsoft limitation regarding Docker volumes:
"We support mapping a whole second drive letter, but for now, not
portions of it. "
You have to just mount the complete d drive, as d:
Other options such as root (d:\), or paths (d:\somefolder) won't work with the second drive.
In your case, that means doing something like:
docker run -it -v d: alpine ls /d/data
If that creates an empty d folder inside your container, that means you're hitting permission issues within the drive.
Note that even if the issue comment is from 2016, seems like the limitation is still kicking in...

How do I transfer a volume's data to another volume on my local host in docker?

I did
docker run -v /jenkins_home:/var/jenkins_home jenkins/jenkins:alpine
on Windows (with docker installed as a linux container).
However, after configuring jenkins on that container, I now wanted to transfer the data in that /jenkins_home volume into a C:\jenkins_home folder on my local windows host machine\another machine.
Any way I can get the data from the /jenkins_home to c:/jenkins_home?
I know I should have made it
docker run -v c:/jenkins_home:/var/jenkins_home jenkins/jenkins:alpine
at the start but mistakes were made and I was wondering how do I fix that as the above suggestion?
Tried running
docker run -it -p 8080:8080 -p 50000:50000 --volumes-from jenkins_old -v c:/jenkins_home:/var/jenkins_home --name jenkins_new jenkins/jenkins:alpine
but it doesn't transfer the data over using the new c:\jenkins_home folder
docker run -v /jenkins_home:/var/jenkins_home jenkins/jenkins:alpine
Can't get the data to transfer over from the /jenkins_home folder to c:\jenkins_home folder.
I don't know where the /jenkins_home would map to on windows, but you could try this:
docker run -it --rm -v /jenkins_home:/from -v c:\jenkins_home:/to alpine cp -r /from /to

why do i keep seeing nginx index.html on localhost when i run my docker image

I installed and run nginx on my linux machine to understand the configurations etc. After a while i decided to remove it safely by following this thread in order to use it in docker
By following this documentaion i run this command
sudo docker run --name ngix -d -p 8080:80 pillalexakis/myrestapi:01
And i saw ngix's homepage at localhost
Then i deleted all ngix images & stopped all containers and i also run this command
sudo docker system prune -a
But now restarted my service by this command
sudo docker run -p 192.168.2.9:7777:8085 phillalexakis/myfirstapi:01 and i keep seeing at localhost ngix index.html
How can i totally remove it ?
Note: I'm new with docker and i might have missed a lot of things. Let me know what extra docker commands should i run in order provide better information.
Assuming your host have been preparing as below
your files (index.html, js, etc) under folder - /myhost/nginx/html
your nginx configuration - /myhost/nginx/nginx.conf
Solution
map your files (call volume) on the fly from outside docker image via docker cli
This is the command
docker run -it --rm -d -p 8080:80 --name web \
-v /myhost/nginx/html:/usr/share/nginx/html \
-v /myhost/nginx/nginx.conf:/etc/nginx/nginx.conf \
nginx
copy your files into docker image by build your own docker image via Dockerfile
This is your Dockerfile under /myhost/nginx
FROM nginx:latest
COPY ./html/index.html /usr/share/nginx/html/index.html
This is the command to build your docker image
cd /myhost/nginx
docker build -t pillalexakis/nginx .
This is the command to run your docker image
docker run -it --rm -d -p 8080:80 --name web \
pillalexakis/nginx

cannot share a folder with docker container

I am running a python interactive docker container on Ubuntu 14.04 using docker 17.03.1. I want to share files between local host and docker container so that files I create in the container are visible in the local directory and vice-versa. However when I run the following command I see an empty working directory in the container with no files.
docker run -e USER=$USER -e USERID=$UID -v /home/watts/python:/home/watts/python -w=/home/watts/python -p 8888:8888 --rm -it watts/python jupyter notebook --no-browser --notebook-dir=/home/watts/python --allow-root
I just run this command:
docker run -v `pwd`/home/watts/python:/home/watts/python -it kaggle/python /bin/bash
And after that, I started creating a few files both host and container. All files are visible in both sides.
Hopefully this will help.

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)

Resources