Whenever I try to use volumes with a docker container, I end up with an empty folder. I am using minikube I am struggling to figure out what is going on.
At first, I thought it may be due to the folder being on a different partition, hence some weird permission or mount option.
Unfortunately, it does not seems to be that easy. I am able to replicate it even when mounting /tmp
. Read the following section.
I also thought that given that minikube is running on top of VirtualBox, I needed to share the folder there. Didn't change the result.
I am using this small script to test it.
mkdir -p /tmp/foo
touch /tmp/foo/foo
docker run --entrypoint "/bin/ls" --rm -ti --net=host -v "/tmp/foo:/bar" yikaus/alpine-bash -lha /bar
The result is an empty folder
drwxr-xr-x 2 root root 40 Sep 19 13:42 .
drwxr-xr-x 1 root root 4.0K Sep 19 13:43 ..
ll -d /tmp/
drwxrwxrwt 18 root root 2940 Sep 19 15:46 /tmp/
15:47 $ ll -d /tmp/foo/
drwxr-xr-x 2 raffaele raffaele 60 Sep 19 15:46 /tmp/foo/
Version
docker --version
Docker version 18.09.8, build 00dd43dd
Info with docker --info
Containers: 36
Running: 26
Paused: 0
Stopped: 10
Images: 33
Server Version: 18.06.3-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: N/A (expected: a592beb5bc4c4092b1b1bac971afed27687340c5)
init version: N/A (expected: )
Security Options:
seccomp
Profile: default
Kernel Version: 4.15.0
Operating System: Buildroot 2018.05
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.84GiB
Name: minikube
ID: 3BHX:6UKW:L5YR:TOSA:QKDD:YUKF:4POD:IMY7:CBCM:DCG2:G5A3:2JD2
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
provider=virtualbox
Experimental: false
Insecure Registries:
10.96.0.0/12
127.0.0.0/8
Live Restore Enabled: false
/etc/fstab
/dev/sda5 / jfs noatime 0 1
/dev/sda7 /data jfs users,exec,noatime,umask=0022 0 1
Linux shangrila 4.14.52-gentoo #1 SMP Fri Mar 15 18:33:01 CET 2019 x86_64 Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz GenuineIntel GNU/Linux
XTERM_256_COLORS=1
XDG_MENU_PREFIX=e-
E_START_MANAGER=1
LANG=en_GB.utf8
GDM_LANG=en_GB.utf8
QT_GRAPHICSSYSTEM=raster
LESS=-R -M --shift 5
DISPLAY=:0.0
OPENGL_PROFILE=xorg-x11
QT_STYLE_OVERRIDE=gtk2
E_DATA_DIR=/usr/share/enlightenment
__GIT_PROMPT_SHOW_UPSTREAM=
CONFIG_PROTECT_MASK=/etc/sandbox.d /etc/fonts/fonts.conf /etc/gentoo-release /etc/gconf /etc/terminfo /etc/dconf /etc/ca-certificates.conf /etc/texmf/web2c /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/revdep-rebuild
EDITOR=/usr/bin/vi
E_BIN_DIR=/usr/bin
JAVA_HOME=/home/raffaele/.gentoo/java-config-2/current-user-vm
E_PREFIX=/usr
GCC_SPECS=
XDG_VTNR=7
VIRTUAL_ENV=/data/work/<redacted>/venv2
PANTS=ON
E_TAINTED=NO
MOZ_USE_XINPUT2=1
VTK_DIR=/usr/lib64/vtk-7.1
XDG_SESSION_ID=2
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/raffaele
VBOX_APP_HOME=/usr/lib64/virtualbox
USER=raffaele
PAGER=/usr/bin/less
DESKTOP_SESSION=enlightenment
TERMINOLOGY=1
DOCKER_CERT_PATH=/home/raffaele/.minikube/certs
QT_QPA_PLATFORMTHEME=gtk2
PWD=/data/work/<redacted>
SSH_ASKPASS=/usr/bin/enlightenment_askpass
HOME=/home/raffaele
MANPAGER=manpager
__GIT_PROMPT_IGNORE_STASH=
ITK_DATA_ROOT=/usr/share/itk/data
__GIT_PROMPT_SHOW_UNTRACKED_FILES=all
XDG_SESSION_TYPE=x11
GSETTINGS_BACKEND=dconf
XDG_DATA_DIRS=/usr/share/enlightenment:/usr/local/share:/usr/share
USE_CCACHE=1
JDK_HOME=/home/raffaele/.gentoo/java-config-2/current-user-vm
XDG_SESSION_DESKTOP=enlightenment
E_IPC_SOCKET=/run/user/1000/e-raffaele@0/4502
E_LIB_DIR=/usr/lib64
E_LOCALE_DIR=/usr/share/locale
GTK_MODULES=canberra-gtk-module
E_START_TIME=1568876560.1
E_ICON_THEME=hicolor
DOCKER_TLS_VERIFY=1
MAIL=/var/mail/raffaele
__GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=1
VTK_DATA_ROOT=/usr/share/vtk/data
CONFIG_PROTECT=/usr/share/maven-bin-3.3/conf /usr/share/maven-bin-3.6/conf /usr/share/gnupg/qualified.txt /usr/share/config
TERM=xterm-256color
SHELL=/bin/bash
DOCKER_HOST=tcp://192.168.99.100:2376
XDG_SESSION_CLASS=user
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
JAVAC=/home/raffaele/.gentoo/java-config-2/current-user-vm/bin/javac
XDG_CURRENT_DESKTOP=Enlightenment
E_SCALE=1.200
E_RESTART=1
XDG_SEAT=seat0
SHLVL=1
GIT_BRANCH=<REDACTED>
VTKHOME=/usr
MANPATH=/home/raffaele/.gentoo/java-config-2/current-user-vm/man:/usr/share/gcc-data/x86_64-pc-linux-gnu/6.4.0/man:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.30/man:/usr/lib/llvm/7/share/man:/usr/lib/llvm/6/share/man:/usr/lib/llvm/5/share/man:/etc/java-config-2/current-system-vm/man/:/usr/lib64/php7.2/man/:/usr/lib64/php7.3/man/:/usr/local/share/man:/usr/share/man:/usr/share/rust-1.34.2/man
SUDO_ASKPASS=/usr/bin/enlightenment_askpass
WINDOWID=8388625
GDMSESSION=enlightenment
E_CONF_PROFILE=standard
LOGNAME=raffaele
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
DESKTOP=Enlightenment
XDG_RUNTIME_DIR=/run/user/1000
XAUTHORITY=/home/raffaele/.Xauthority
ANT_HOME=/usr/share/ant
DOCKER_API_VERSION=1.35
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_CONFIG_DIRS=/usr/etc/xdg:/etc/xdg
PATH=/data/work/<redacted>/venv2/bin:/home/raffaele/Applications/.bin:/home/raffaele/.cargo/bin:/usr/lib/llvm/7/bin:/usr/lib/llvm/6/bin:/usr/lib/llvm/5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/games/bin:/home/raffaele/.local/bin
PS1=(\[\033[0;34m\]venv2\[\033[0;0m\]) \[\033[0;31m\]✘-1\[\033[0;0m\] \[\033[0;33m\]\w\[\033[0;0m\] [\[\033[0;35m\]feature/TIQ04-16183\[\033[0;0m\]|\[\033[0;34m\]✚ 6407\[\033[0;0m\]\[\033[0;36m\]…24938\[\033[0;0m\]\[\033[0;0m\]] \n\[\033[0;37m\]$(date +%H:%M)\[\033[0;0m\] $
INFOPATH=/usr/share/gcc-data/x86_64-pc-linux-gnu/6.4.0/info:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.30/info:/usr/share/info
E_START=/usr/bin/enlightenment_start
LESSOPEN=|lesspipe %s
_=/usr/bin/env
Your docker host appears to be running inside of a VM as seen with this variable:
DOCKER_HOST=tcp://192.168.99.100:2376
What you are most likely seeing is the directory inside that VM, and expecting to see them on your parent desktop.
When you mount host files into the container, those files need to be in a directory inside that VM, or the VM needs to have the directory shared from your desktop environment into the VM. Configuring the directory sharing into the VM will be specific to the VM tool. Specific to Minikube, there is the following documentation.
This directs you to run to following for the /tmp/foo
dir:
minikube mount /tmp/foo:/tmp/foo