I'm trying to mount a volume in docker-compose between my Windows host and linux container:
version: '3'
volumes:
my_vol:
driver_opts:
type: cifs
o: "addr=xxx.xx.com,username=<USER>,password=<PWD>"
device: "//xxx.xx.com/<MY_FOLDER>"
services:
cont:
container_name: Cont
privileged: true
build: .
volumes:
- my_vol:/mnt/my_vol
command: tail -f /dev/null
Now I've tried a couple of different volumes to mount but I either get this error:
Error response from daemon: failed to mount local volume: mount
//xxx.xx.com/<MY_FOLDER>:/var/lib/docker/volumes/cont_my_vol/_data, data:
addr=XXX.XXX.X.XXX, username=<USER>, password=<PWD>: no such file or directory
or this one:
Error response from daemon: failed to copy file info for
/var/lib/docker/volumes/cont_my_vol/ data: failed to utime
/var/lib/docker/volumes/cont_my_vol/_data: permission denied.
It seems to me like I don't have permissions to mount the folder on the destination: /mnt/my_vol rather than the source (//xxx.xx.com/<MY_FOLDER>) but I can't explain why...
Related
Does anyone know how to mount an NFS to a docker container using docker compose? I keep getting the same error each time I run 'docker compose up':
Error response from daemon: error while mounting volume '/var/lib/docker/volumes/test_data/_data': failed to mount local volume: mount /etc/hapee-2.2/certs:/var/lib/docker/volumes/test_data/_data, data: addr=10.15.50.27,nolock,soft: invalid argument
Exports file from the NFS appears to be set up correctly. I've tried deleting '/home/' from the file path as well. IP address is redacted.
/etc/hapee-2.2/certs <ipaddressofpc>(rw,sync,no_subtree_check,no_root_squash)
I keep suspecting the docker-compose.yml, but I'm not sure what the issue with it would be
version: '3.7'
services:
hapee:
image: haproxy:2.2
container_name: test
restart: always
ports:
- "80:80"
- "443:443"
- "8888:8888"
volumes:
- data:/etc/hapee-2.2/certs
logging:
options:
max-size: 100m
max-file: "3"
volumes:
data:
driver_opts:
type: "nfs"
o: "addr=10.15.50.27,nolock,soft,ro"
device: "/etc/hapee-2.2/certs"
Alternatively, does anyone know another method of mounting SSL certificates to an HA Proxy container with docker compose?
Thanks!
I would like to mount a directory from inside a docker to my linux Ubuntu host machine using docker-compose.yml.
The directory in the docker container is /usr/local/XXX and I want to mount it on /home/Projects/XX
How can I make it happen?
This is my docker-compose.yml file:
version: '3'
services:
MyContainer:
image: XX.XXX.XXX.XXX:XXXX/XXX/MyContainer:latest
restart: always
container_name: MyContainer
hostname: MyContainer_docker
privileged: true
ports:
- "XXXX:XX"
volumes:
- /home/Project/workspace/XXX/XXXX:/home/XX
environment:
- ...
extra_hosts:
- ...
networks:
net_plain3:
ipv4_address: ...
networks:
# ...etc...
It is possible with the right driver options.
Technically, you still mount the host directory to the container, but the result is that the host directory is populated with the data in the container directory. Usually it's the other way around. That's why you need those driver options.
services:
somebox:
volumes:
- xx-vol:/usr/local/XXX
volumes:
xx-vol:
driver: local
driver_opts:
type: none
o: bind
device: /home/Projects/XX
Empty named volumes are initialized with the content of the image at the mount location when the container is created.
- bmitch
So the key here is to create a named volume that uses as device the desired location on the host.
As a full working demonstration.
I create the following Dockerfile to add text file in the /workspace dir:
FROM busybox
WORKDIR /workspace
RUN echo "Hello World" > hello.txt
Then a compose.yaml to build this image and mount a volume with these driver options:
services:
databox:
build: ./
volumes:
- data:/workspace
volumes:
data:
driver: local
driver_opts:
type: none
o: bind
device: /home/blue/scrap/vol/data
Now I run the below commands:
$ mkdir data
$ docker-compose up
[+] Running 1/0
⠿ Container vol-databox-1 Created 0.0s
Attaching to vol-databox-1
vol-databox-1 exited with code 0
$ cat /home/blue/scrap/vol/data/hello.txt
Hello World
As you can see, the hello.txt file ended up on the host. It was not created after container startup but was already inside the container's file system when the container started, since it has been added during build.
That means, it is possible to populate a host directory with data from a container in such a way that the data doesn't have to be generated after volume mount, which is usually the case.
I'm trying to mount a directory in my organization's server (Y:/some/path) to a docker container. My docker-compose.yml looks like this:
services:
dagit:
volumes:
- type: bind
source: Y:/some/path
target: /data
build:
context: .
dockerfile: Dagit.Dockerfile
ports:
- "3000:3000"
container_name: dagit-container
dagster:
volumes:
- type: bind
source: Y:/some/path
target: /data
build:
context: .
dockerfile: Daemon.Dockerfile
container_name: dagster-container
tty: true
env_file: .env
I have shared Y:/some/path with Docker. On docker compose up -d --build, I get the following error: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /host_mnt/uC/my_ip/some/path. How can I properly mount such a directory? Also, what would be the correct way to declare this mount in the top level volumes key and reference it in both services so I don't have to duplicate the code?
Take the following docker-compose.yml file:
version: '3.9'
services:
DockerA:
image: ubuntu:latest
container_name: DockerA
command: ["sleep", "300d"]
volumes:
- "./data:/root/data"
DockerB:
image: ubuntu:latest
container_name: DockerB
command: [ "sleep", "300d" ]
volumes:
- "./data:/root/data"
volumes:
data:
And next to that file (same directory) create a directory called 'data'.
Now start the dockers with:
docker-compose up -d
If you enter the DockerA container and create something in the data directory:
docker exec -it DockerA /bin/bash
# cd /root/data
# echo "Hello World!" > x.txt
then go into DockerB
docker exec -it DockerB /bin/bash
# cd /root/data
# cat x.txt
you will see the same contents of x.txt.
Now back to the host and check the x.txt file in your ./data directory.
Also same contents.
If you edit x.txt on the Host, it will immediatelly be reflected in both DockerA and DockerB.
Assuming your enterprise share is Windows/SAMBA CIFS/SMB-Share, add it as Volume directly and not via Windows mount.
volumes:
shared_folder:
driver_opts:
type: cifs
o: username=smbuser,password=smbpass,uid=UID for mount,gid=gid for mount,vers=3.0,rw
device: //hostname_or_ip/folder
Version depends on your Server Type, rw = readwrite
Then map the volume
services:
dagit:
volumes:
- shared_folder:/root/data
I need to mount a disk using docker-compose.
Currently I can assemble using docker service create, this way:
docker service create -d \
--name my-service \
-p 8888:80 \
--mount='type=volume,dst=/usr/local/apache2/htdocs,volume-driver=local,volume-opt=type=xfs,volume-opt=device=/dev/sdd' \
httpd
My docker-compose.yml looks like this:
version: '3.8'
services:
my-service:
image: httpd
ports:
- '80:80'
volumes:
- type: volume
source: my-vol
target: /usr/local/apache2/htdocs
volumes:
my-vol:
driver: local
driver_opts:
type: xfs
o: bind
device: '/dev/sdd'
When uploading the service with docker-compose up I get the error:
"failed to mount local volume: mount /dev/sdd:/var/lib/docker/volumes/apache_my-vol/_data, flags: 0x1000: not a directory"
How can I configure my docker-compose.yml to be able to mount a disk?
*Sorry, my bad english..
The o: line matches options you'd pass to the ordinary Linux mount(8) command. o: bind manually creates a bind mount that attaches part of the filesystem somewhere else; this is the mechanic behind Docker's bind-mount system. The important thing that changes here is that it causes the device: to actually be interpreted as a (host-system) directory to be remounted, and not a device.
Since you're trying to mount a physical device, you don't need the o: bind option. If you delete that option, the device: will be interpreted as a device name and you'll be able to mount your disk.
permission denied errors when attempting to mount an nfs drive to a docker container using a docker-compose file.
This error only applies when running Docker for Windows. I am able to successfully mount the drive on an Ubuntu host.
docker-compose file
version: '2'
services:
builder:
image: some_image
ports:
- "8888:8080"
volumes:
- "nfsmountCC:</container/path>"
volumes:
nfsmountCC:
driver: local
driver_opts:
type: nfs
o: addr=<nfs_IP_Address>
device: ":</nfs/server/dir/path>"
Docker for Windows Produces
ERROR: for test_1 Cannot start service builder: b"error while mounting volume '/var/lib/docker/volumes/test-master_nfsmountCC/_data': error while mounting volume with options: type='nfs' device=':</nfs/server/dir/path>' o='addr=<nfs_IP_Address>': permission denied"
The following worked for me with Docker Toolbox on Windows 7 mounting a NFS volume from an Ubuntu server:
NFS Server side:
allow the nfs and mountd services on your firewall (if you have one) on the NFS server
add the insecure option in each relevant entry of your '/etc/exports' file
Docker client side: add the hard and nolock options to the NFS volume definition
version: '3.7'
services:
builder:
image: some_image
ports:
- "8888:8080"
volumes:
- "nfsmountCC:</container/path>"
volumes:
nfsmountCC:
driver: local
driver_opts:
type: nfs
o: "addr=<nfs_IP_Address>,rw,hard,nolock"
device: ":</nfs/server/dir/path>"