Cannot mount Config directory in Nextcloud Docker container - docker

I'm trying to create a custom Nextcloud config locally, then have the ability to mount it to the appropriate folder using volumes as defined here: https://github.com/nextcloud/docker#persistent-data. All the volume mounts work except for the config mount... Why is that being treated differently here?
Steps to reproduce
0) Enter a new/emptry directory (containing no sub-directories or additional files).
1) Create a docker-compose.yml file containing only the below contents:
version: "3.4"
services:
nextcloud:
image: nextcloud:latest
volumes:
- "./nextcloud/custom_apps:/var/www/html/custom_apps"
- "./nextcloud/config:/var/www/html/config"
- "/data/nextcloud:/var/www/html/data"
- "./themes:/var/www/html/themes"
2) docker-compose up -d
Expected behavior
Work. I should be able to see the /var/www/html/config contents locally at ./nextcloud/config, and then insert a customer config.php, which is then updated within the container.
Actual behavior
An ERROR when bringing up the container, specific to the config directory. If I remove the ./nextcloud/config:/var/www/html/config volume mount above, then the container will start without error.
ERROR message
ERROR: for nextcloud Cannot start service nextcloud: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\"/home/user/Nextcloud-test/nextcloud/config\\" to rootfs \\"/var/lib/docker/overlay2/41b567141e23b16cf5e4f99f4c33703fc9a533aa5a4bef68fbba70a74842ca88/merged\\" at \\"/var/lib/docker/overlay2/41b567141e23b16cf5e4f99f4c33703fc9a533aa5a4bef68fbba70a74842ca88/merged/var/www/html/config\\" caused \\"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
ERROR: Encountered errors while bringing up the project.
Server configuration
Operating system:
Operating System: Debian GNU/Linux 10 (buster)
Kernel: Linux 4.19.0-8-cloud-amd64
Architecture: x86-64
Image
nextcloud:latest (apache)

I could not reproduce using your steps (Ubuntu 18.04).
From here, running docker-compose up -d then docker-compose logs, I see no errors. Then, when running docker inspect on the container, I see the following:
...
"Volumes": {
"/var/www/html": {},
"/var/www/html/config": {},
"/var/www/html/custom_apps": {},
"/var/www/html/data": {},
"/var/www/html/themes": {}
},
...
Which suggests the mount has worked without problem.
What I suggest you do:
Check the directory ./nextcloud/config exists and is not a file
Check your Docker and Docker Compose installation is up-to-date
Try running the Docker container with docker run -it -v ./nextcloud/config:/var/www/html/config <containername> /bin/bash to explore if the mount works manually
Try to do the same on a minimal example such as the Getting started example

Related

Docker compose 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)?

I'm trying to take a config file and replace the already existing default.conf in nginx.
My super simple Docker compose:
version: '3.3'
services:
qwc-api-gateway:
image: nginx:1.19
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
For convenience, I even published the two files here:
https://github.com/Xentraxx/qwc-docker
The problem: If I try to build a stack from this repository in portainer, it fails with the error message:
Error response from daemon:
failed to create shim:
OCI runtime create failed:
runc create failed:
unable to start container process:
error during container init:
error mounting "/data/compose/7/default.conf" to rootfs at "/etc/nginx/conf.d/default.conf":
mount /data/compose/7/default.conf:/etc/nginx/conf.d/default.conf (via /proc/self/fd/6),
flags: 0x5001: 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
If I run docker-compose up -d locally, the container starts and I can see in the logs that the default.conf has my desired values.
I couldn't find anything helpful for this online, only people saying that the source file probably doesn't exist.
So feel free to take my repository, try to create a stack from it in Portainer and let me know what I am doing wrong. Because I have no idea anymore.
Also please ignore that the container crashes after it started. This is not related.
I had the same problem with gitlab-runner. I use dind, and solution is to share folder which will be mount between containers: between gitlab-runner and docker-with-socket containers:
at /etc/gitlab-runner/config.toml
...
volumes = ["/cache","/opt"]
...
In your case with error
error mounting "/data/compose/7/default.conf"
you should share /data folder.

airflow breeze init failed

I followed the instructions to initialize breeze environment: https://github.com/apache/airflow/blob/main/CONTRIBUTORS_QUICK_START.rst#setting-up-breeze
Seems like the image is built but failed to start.Something wrong with my environment?
Good version of docker 20.10.9.
Python version: 3.8
Backend: mysql
No need to rebuild the image: none of the important files changed
Use CI image.
Branch name: main
Docker image: ghcr.io/apache/airflow/main/ci/python3.8
Airflow source version: 2.3.0.dev0
Python version: 3.8
Backend: mysql 5.7
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 "/mnt/c/Users/binglilun/source/repos/doowhtron/airflow/scripts/in_container/entrypoint_ci.sh" to rootfs at "/entrypoint" 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.
The problem is fixed.
Key things for running breeze on my wsl environment are:
Upgrade to wsl2(my distribution is ubuntu)
checkout the source to ~/ instead of /mnt/c/
run docker daemon inside wsl2(not using docker destop)
enable wsl's network by setting /etc/resolv.conf(putting nameserver 8.8.8.8)
add "--network host" parameter to docker_v build(_build_images.sh), otherwise internet cannot be connected
install yarn and add "--ignore-engines" to yarn install (compile_assets.sh)
And breeze works for me now.

Mount volume for remote Docker context via SSH

I'm deploying few Docker services via docker-compose with remote context. I configured it to use SSH:
docker context create remote --docker "host=ssh://user#my.remote.host"
docker context use remote
On the remote host I have multiple configuration files which I want to mount into the Docker. It's working fine when I'm trying with docker CLI:
docker run -v /home/user/run:/test -it alpine:3.11
# ls -la /test
-> shows remote files correctly here
But when I'm starting it using docker-compose with config file:
version: "3.3"
services:
nginx:
image: nginx:1.17.10-alpine
container_name: nginx
restart: unless-stopped
volumes:
- ${HOME}/run/nginx.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
- "443:443"
It's trying to mount local files instead of remote for some reason and fails with error:
ERROR: for nginx Cannot start service nginx: OCI runtime create failed: container_linux.go:296: starting container process caused "process_linux.go:398: container init caused \"rootfs_linux.go:58: mounting \\\"/home/local-user/run/nginx.conf\\\" to rootfs \\\"/hdd/docker/overlay2/c869ef9f2c983d33245fe1b4360eb602d718786ba7d0245d36c40385f7afde65/merged\\\" at \\\"/hdd/docker/overlay2/c869ef9f2c983d33245fe1b4360eb602d718786ba7d0245d36c40385f7afde65/merged/etc/nginx/nginx.conf\\\" caused \\\"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
Is it possible to mount remote resources via docker-compose similar to standard Docker CLI?
You need to explicitly set DOCKER_HOST to access your remote docker host from docker-compose.
From the compose documentation
Compose CLI environment variables
DOCKER_HOST
Sets the URL of the docker daemon. As with the Docker client, defaults
to unix:///var/run/docker.sock.
In your given case, docker context use remote sets current context to remote
only for your docker command. docker-compose still uses your default (local) context. In order for docker-compose to detect it, you must pass it via the DOCKER_HOST environment variable.
Example:
$ export DOCKER_HOST=ssh://user#my.remote.host
$ docker-compose up

How do I create a docker image from dockerfile and then make a config file available on a volume when running the image from docker-compsose

I am creating a docker container running a python script that collects telemetry. The dockerfile looks like this.
FROM python:3.7-alpine
WORKDIR /app
COPY src/requirements.txt ./
RUN pip install -r requirements.txt
COPY src /app
CMD [ "python", "main.py" ]
inside the folder 'src' is a folder 'config' with 'config.json' saved
src/config/config.json
the docker-compose file looks like this
version: '2.2'
services:
umpmfd:
container_name: mfdwebsockets
build: mfdwebsockets
network_mode: "host"
restart: always
volumes:
- "/home/xtp/config.json:/app/config/config.json"
depends_on:
- influxdb
- grafana
I want to have the 'config.json' file available on the host machine so I can change the config with out stopping and restarting the container. At the moment I am getting this error.
ERROR: for mfdwebsockets Cannot start service umpmfd: OCI runtime
create failed
: container_linux.go:346: starting container process caused
"process_linux.go:44
9: container init caused \"rootfs_linux.go:58: mounting
\\"/home/xtp/config.jso
n\\" to rootfs
\\"/var/lib/docker/overlay2/c5a992a5717f2d510e75056ba38ad4075a0
31e73ca010fef5da8328ad366eaad/merged\\" at
\\"/var/lib/docker/overlay2/c5a992a
5717f2d510e75056ba38ad4075a031e73ca010fef5da8328ad366eaad/merged/app/config/conf
ig.json\\" caused \\"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
ERROR: for umpmfd Cannot start service umpmfd: OCI runtime create
failed: conta
iner_linux.go:346: starting container process caused
"process_linux.go:449: cont
ainer init caused \"rootfs_linux.go:58: mounting
\\"/home/xtp/config.json\\" t
o rootfs
\\"/var/lib/docker/overlay2/c5a992a5717f2d510e75056ba38ad4075a031e73ca
010fef5da8328ad366eaad/merged\\" at
\\"/var/lib/docker/overlay2/c5a992a5717f2d
510e75056ba38ad4075a031e73ca010fef5da8328ad366eaad/merged/app/config/config.json
\\" caused \\"not a directory\\"\"": unknown: Are you trying to
mount a direc
tory onto a file (or vice-versa)? Check if the specified host path
exists and is
the expected type
What do I need to change to get this config.json file available as a volume on the host machine?
Are you trying to mount a directory onto a file (or vice-versa)?
This is exactly what error message suggests.
Mount directories instead of files.
volumes:
- "/home/xtp:/app/config"

Issue mounting docker volume with docker-compose

My Scenario
I am trying to build docker swarm with docker-compose.yml file
version: '3'
services:
myapp-nginx:
image: nginx:1.10
volumes:
- ./nginx/certs:/etc/nginx/certs
ports:
- 80:80
- 443:443
using build command as below
$ docker stack deploy --compose-file docker-compose.yml myapp
Creating network myapp_default
Creating service myapp_myapp-nginx
My system have Docker Version 17.03.1-ce-mac5 (16048)
Problem
Volumes mounts are not working, If I comment out volumes: - ./nginx/certs:/etc/nginx/certs then everything works fine.
Otherwise nginx doesn't work at all, I see
CAGTAM1059934:docker iskumar$ docker stack ps myapp
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
efjia8b7y6jd myapp_myapp-nginx.1 nginx:1.10 manager1 Ready Rejected 5 seconds ago "invalid mount config for type…"
c9c6ogh11osi \_ myapp_myapp-nginx.1 nginx:1.10 worker2 Shutdown Rejected 10 seconds ago "invalid mount config for type…"
iveikxpnbq6x \_ myapp_myapp-nginx.1 nginx:1.10 worker1 Shutdown Rejected 15 seconds ago "invalid mount config for type…"
Is there any special way to mount volumes in docker-compose v3?
You must use absolute paths when mounting volumes, also with docker run.
$ docker run --rm -it -v ./eos:/eos:ro ubuntu
docker: Error response from daemon: create ./eos: "./eos" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intented to pass a host directory, use absolute path.
See 'docker run --help'
I was running docker stack deploy from my macbook instead on boot2docker VMs. Which is why system couldn't find those network mount source, even though I had manager1 activated using eval $(docker-machine env manager1)
First I used --no-trunc argument to view full error message.
$> docker node ps --no-trunc
---
Showed "invalid mount config for type "bind": bind source path does not exist"
---
After that copies the files from host system (My MacBook) to VM and launching stack worked fine.
Credit to https://github.com/docker/docker/issues/31202#issuecomment-281312704

Resources