Mounting Folders in Docker: Windows Host, Windows Image - docker

How to use the docker mount option to share a local folder in Docker Container? Currently, I am using this command but I am not being successful.
docker run --mount source='c:\temp',target='c:\temp' -i newname:latest
I get this error -
C:\Program Files\Docker\docker.exe: Error response from daemon: invalid mount config for type "volume": invalid volume name.
My environment:
Host: Windows Server, version 1709
Docker Container: Windows Server Core, v1709

You need to use bind mount. Example below maps your host directory c:\users\public\ to the one which is inside container c:\users\public and then outputs content of that directory.
PS C:\Users\gsuvalia> docker run --rm --mount type=bind,source=c:\users\public\,destination=c:\users\public\ microsoft/nanoserver powershell get-childitem c:\users\public
Directory: C:\users\public
Mode LastWriteTime Length Name
---- ------------- ------ ----
d-r--- 12/1/2017 10:16 PM Documents
d-r--- 7/16/2016 6:47 AM Downloads
d-r--- 7/16/2016 6:47 AM Music
d-r--- 12/1/2017 10:16 PM Pictures
d----- 8/22/2017 10:26 PM Roaming
d-r--- 7/16/2016 6:47 AM Videos

Related

docker mount - Error response from daemon: invalid mount config for type "bind"

I am facing an issue with mounting a host directory into docker container with both -v and --mount options.
Using mount:
docker run --mount type=bind,source=/home/myuser/docker_test/out_dir,target=/home/out_dir --user 12345:1000 -it docker-name:0.1 bash
docker: Error response from daemon: invalid mount config for type "bind": stat /home/myuser/docker_test/out_dir: permission denied.
But I am able to do stat on this directory.
stat /home/myuser/docker_test/out_dir
File: '/home/myuser/docker_test/out_dir'
Size: 4096 Blocks: 8 IO Block: 32768 directory
Device: 33h/51d Inode: 9275022755226025350 Links: 2
Access: (0770/drwxrwx---) Uid: (12345/ myuser) Gid: ( 1000/ hercules)
Access: 2022-12-01 02:12:54.430582000 -0500
Modify: 2022-12-01 02:12:38.239629000 -0500
Change: 2022-12-01 02:12:38.239629000 -0500
Birth: -
Using -v:
docker run -v /home/myuser/docker_test/out_dir:/home/out_dir --user 12345:1000 -it docker-name:0.1:0.1 bash
docker: Error response from daemon: error while creating mount source path '/home/myuser/docker_test/out_dir': mkdir /home/myuser/docker_test: permission denied.
ERRO[0000] error waiting for container: context canceled
I don't know why it's trying to do mkdir but /home/myuser/docker_test already exists and is writable for the current user.
Am I missing something here?
BTW - /home is a NFS mounted directory.
EDIT: mounting /tmp worked. So this means it is related to the NFS mounted directory /home.
EDIT 2
I am working on a network machine where I don’t have root (sudo) access.
The docker service is installed by root user.
/home/myuser/docker_test/out_dir has 700 (rwx------) permissions. If I change the permission to 755, it will work. But I can’t change the directory permissions.
My question is why stat is failing when the user starting the docker has the permissions to access the source directory?
Is the stat being called by the docker executable as some ‘other’ user?
Use:
sudo docker run -v /home/myuser/docker_test/out_dir:/home/out_dir --user 12345:1000 -it docker-name:0.1:0.1 bash

Aerospike Connect to kafka: docker: Error response from daemon: invalid mode: /etc/aerospike-kafka-outbound/aerospike-kafka-outbound.yml

I am trying Aerospike Connect to Kafka.
OS: Windows
I referred https://enterprise.aerospike.com/docs/connect/streaming-from-asdb/installing/from-asdb-to-kafka-installing.html.
I referred: '# With Aerospike 5.0 and later' for deploying on docker
I have these running in docker:
My Windows path for the file: C:/aerospike-kafka-outbound/aerospike-kafka-outbound.yml
C:\Users\Nupur>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1114b8a97406 aerospike/aerospike-kafka-outbound:4.0.0 "/bin/sh -c '/opt/${…" 37 seconds ago Up 29 seconds compassionate_hofstadter
93343be1d481 aerospike/aerospike-tools "wrapper aql -h 172.…" 4 hours ago Up 4 hours dreamy_mendeleev
5f00ee532c4e aerospike/amc "/opt/amc/amc ' -con…" 8 days ago Up 4 hours 0.0.0.0:8081->8081/tcp aerospike-consoles
a81ff04dbd74 aerospike/aerospike-server-enterprise "/usr/bin/tini -r SI…" 8 days ago Up 4 hours 0.0.0.0:3000-3002->3000-3002/tcp aerospike
Error:
C:\Users\Nupur>docker run -p 8080:8080 -v /C:/aerospike-kafka-outbound/aerospike-kafka-outbound.yml:/etc/aerospike-kafka-outbound/aerospike-kafka-outbound.yml aerospike/aerospike-kafka-outbound:4.0.0
docker: Error response from daemon: invalid mode: /etc/aerospike-kafka-outbound/aerospike-kafka-outbound.yml.
See 'docker run --help'.
As for the front slash used in Windows path, on using backslash:
C:\Users\Nupur>docker run -p 8080:8080 -v C:\\aerospike-kafka-outbound\\aerospike-kafka-outbound.yml:/etc/aerospike-kafka-outbound/aerospike-kafka-outbound.yml aerospike/aerospike-kafka-outbound:4.0.0
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/run/desktop/mnt/host/c/aerospike-kafka-outbound/aerospike-kafka-outbound.yml" to rootfs at "/etc/aerospike-kafka-outbound/aerospike-kafka-outbound.yml" caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
This is my docker directory:
C:\Users\Nupur>docker exec -it 1114b8a97406 bash
root#1114b8a97406:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root#1114b8a97406:/# cd /etc
root#1114b8a97406:/etc# ls
adduser.conf ca-certificates.conf environment host.conf ld.so.cache machine-id pam.conf rc1.d resolv.conf shells timezone
aerospike-kafka-outbound cron.daily fstab hostname ld.so.conf mke2fs.conf pam.d rc2.d rmt skel update-motd.d
alternatives debconf.conf gai.conf hosts ld.so.conf.d motd passwd rc3.d securetty ssl xattr.conf
apt debian_version group init.d libaudit.conf mtab passwd- rc4.d security subgid
bash.bashrc default group- issue localtime nsswitch.conf profile rc5.d selinux subuid
bindresvport.blacklist deluser.conf gshadow issue.net login.defs opt profile.d rc6.d shadow systemd
ca-certificates dpkg gshadow- kernel logrotate.d os-release rc0.d rcS.d shadow- terminfo
root#1114b8a97406:/etc# cd aerospike-kafka-outbound
root#1114b8a97406:/etc/aerospike-kafka-outbound# ls
aerospike-kafka-outbound.yml
root#1114b8a97406:/etc/aerospike-kafka-outbound#

Docker Compose binding docker cli error: invalid mount config for type "bind": bind source path does not exist: /usr/local/bin/docker

I've been binding the host docker socket and cli so that I can run docker and compose commands from within running containers for over a year without issue but since updating to docker version 20.10.7 and compose version 1.29.2 I can't get my containerised environment to launch without the following error:
invalid mount config for type "bind": bind source path does not exist: /usr/local/bin/docker
Nothing has changed other than I updated Docker Desktop.
The location of the docker binary (symlink) on the host is still present:
0 lrwxr-xr-x 1 aadams-mbp staff 54 3 Aug 2018 /usr/local/bin/docker -> /Applications/Docker.app/Contents/Resources/bin/docker
The target of the symlink permissions look like this:
133608 -rwxr-xr-x 1 root admin 68405888 7 Jul 17:59 /Applications/Docker.app/Contents/Resources/bin/docker
This snippet is from my docker-compose.yaml file:
volumes:
# Bind docker CLI so can run docker commands
# from inside the container. Double check the
# location of the source binary on hosts that
# are not Mac OS. Docker might be in /usr/bin/docker,
# but on Mac OS it is at /usr/local/bin/docker.
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
- type: bind
source: ${DOCKER_BIN_SRC}
target: /usr/bin/docker
The ${DOCKER_BIN_SRC} is pulled in from a .env file (snippet):
##
# Docker bind
#
DOCKER_BIN_SRC=/usr/local/bin/docker
I am running on Mac OS Mojave version 10.14.6

Why is nginx not starting in Windows Server 2019 docker container?

UPDATE 3 (Solution):
I installed the latest Windows updates on my host and specified the exact servercore image to match my updated Windows Server version:
mcr.microsoft.com/windows/servercore:10.0.17763.973
When running the container everything worked as expected.
Original question:
I cannot figure out why nginx doesn't start in my container running on Windows Server 2019.
Nothing is written to the nginx error.log and inspecting the System Event using this answer doesn't provide any information regarding nginx.
When I run nginx directly on the server (i.e. without the container) it starts up fine.
Here are the contents of the dockerfile:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
WORKDIR C:/nginx
COPY /. ./
CMD ["nginx"]
I run the container using the following command:
docker run -d --rm -p 80:80 --name nginx `
-v C:/Data/_config/nginx/conf:C:/nginx/conf `
-v C:/Data/_config/nginx/temp:C:/nginx/temp `
-v C:/Data/_config/nginx/logs:C:/nginx/logs `
nginx-2019
If I exec into the running container I can see that the directory structure is as expected:
Microsoft Windows [Version 10.0.17763.1040]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\nginx>dir
Volume in drive C has no label.
Volume Serial Number is 72BD-907D
Directory of C:\nginx
02/27/2020 06:05 AM <DIR> .
02/27/2020 06:05 AM <DIR> ..
02/27/2020 06:05 AM <DIR> conf
02/27/2020 05:11 AM <DIR> contrib
02/27/2020 05:11 AM <DIR> docs
02/27/2020 05:11 AM <DIR> html
02/27/2020 05:55 AM <DIR> logs
02/27/2020 05:14 AM <DIR> conf
01/21/2020 03:30 PM 3,712,512 nginx.exe
01/21/2020 04:41 PM <DIR> temp
1 File(s) 3,716,608 bytes
9 Dir(s) 21,206,409,216 bytes free
UPDATE 1:
As part of my troubleshooting process I started up a clean VM on Azure and after installing Docker and recreating the Docker image using the exact same files, it starts up as expected.
This means that the issue is specific to my server and not a general issue.
UPDATE 2:
By removing the --rm from the run command I find the following info by running docker ps -a after the container exits:
Exited (3221225785) 4 seconds ago
I can't find any info on what the exit code means.
I was having the same issue, but for me it wasn't docker or nginx, it was the image.
image mcr.microsoft.com/windows/servercore:ltsc2019 was updated on 2/11/2020 and both container and host must have the same update (KB4532691 I think) or some processes may fail silently.
I updated my host, and all is well.
See microsoft-windows-servercore
and you-might-encounter-issues-when-using-windows-server-containers-with-t for more info

Set volume to docker container from wsl from windows 10

In my windows i installed docker and ubuntu 18.4 wsl.So after expose daemon on localhost, i can use windows daemon on ubuntu wsl.
I created a directory's on drive d and i made a file into data directory like below:
PS D:\wsl\data> dir
Directory: D:\wsl\data
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 8/31/2019 2:27 PM 0 New Text Document.txt
PS D:\wsl\data>
after that, i run a postgres container like below on wsl teminal:
$ docker run --name=pg-docker3 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123 -v /mnt/d/wsl/data:/var/lib/postgresql/data mdillon/postgis:11-alpine
After creating container i open container by bash :
$ docker exec -it pg-docker3 bash
This is data postgres directory:
bash-4.4# ls /var/lib/postgresql/data
PG_VERSION pg_commit_ts pg_logical pg_serial pg_subtrans pg_xact postmaster.pid
base pg_dynshmem pg_multixact pg_snapshots pg_tblspc postgresql.auto.conf
data pg_hba.conf pg_notify pg_stat pg_twophase postgresql.conf
global pg_ident.conf pg_replslot pg_stat_tmp pg_wal postmaster.opts
bash-4.4#
as you can see data directory construct in location but when i listed thing's inside data directory i can see my text file that created in host machine !!!
I created a directory inside data directory calld kk.
bash-4.4# ls /var/lib/postgresql/data
PG_VERSION pg_commit_ts pg_logical pg_serial pg_subtrans pg_xact postmaster.pid
base pg_dynshmem pg_multixact pg_snapshots pg_tblspc postgresql.auto.conf
data pg_hba.conf pg_notify pg_stat pg_twophase postgresql.conf
global pg_ident.conf pg_replslot pg_stat_tmp pg_wal postmaster.opts
bash-4.4# ls /var/lib/postgresql/data/data/
kk
bash-4.4#
But not create this directory inside host as you can see:
PS D:\wsl\data> dir
Directory: D:\wsl\data
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 8/31/2019 2:27 PM 0 New Text Document.txt
Where is the /var/lib/postgresql/data/data/ ? and why it not appeared in /mnt/d/wsl/data ?
You must move your mounting path from /mnt to /. In this answer there is the following explanation : Can you run Docker natively on the new Windows 10 (Ubuntu) bash userspace?
Volumes
Take care when adding volumes. The path C:\dir will be visible as /mnt/c/dir on WSL and as /c/dir/ by docker engine. You can overcome it permanently:
sudo bash -c "echo -e '[automount] \nroot = /'>/etc/wsl.conf"
You must exit and reload WSL after making the change to wsl.conf so that WSL reads in your changes on launch.
Regards

Resources