Docker: volume under bind mount? - docker

Here's what I've got:
version: "3.7"
services:
php:
build:
context: .
dockerfile: docker/php.docker
links:
- mariadb
env_file: .env
volumes:
- type: volume
source: webpack_assets
target: /srv/myproject/.webpack
read_only: true
- type: volume
target: /srv/myproject/storage
consistency: delegated
- type: tmpfs
target: /srv/myproject/bootstrap/cache
consistency: delegated
- type: bind
source: .
target: /srv/myproject
read_only: true
consistency: cached
working_dir: '/srv/myproject'
webpack:
image: node:lts
ports:
- '8081:8081'
env_file: .env
volumes:
- type: volume
source: webpack_assets
target: /srv/myproject/.webpack
- type: bind
source: .
target: /srv/myproject
read_only: true
consistency: cached
working_dir: '/srv/myproject'
command: sh -c 'yarn && exec node --max_old_space_size=8192 node_modules/.bin/webpack-dev-server'
volumes:
webpack_assets:
webpack needs read-only access to my project files and it needs to write a special file webpack-assets.json which I've moved under a .webpack directory because I don't think you can mount a single file.
php needs read-only access to this generated file. I would have liked to make it a tmpfs volume but apparently those can't be shared?? The host system doesn't need access to this file.
The problem is I get this error when I try to try to mount the volumes this way:
ERROR: for myproject_webpack_1 Cannot start service webpack: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/var/lib/docker/volumes/myproject_webpack_assets/_data\\\" to rootfs \\\"/var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697c226dc1d1943762/merged\\\" at \\\"/var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697c226dc1d1943762/merged/srv/myproject/.webpack\\\" caused \\\"mkdir /var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697cRecreating myproject_php_1 ... error
ERROR: for myproject_php_1 Cannot start service php: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/var/lib/docker/volumes/myproject_webpack_assets/_data\\\" to rootfs \\\"/var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged\\\" at \\\"/var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged/srv/myproject/.webpack\\\" caused \\\"mkdir /var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged/srv/myproject/.webpack: read-only file system\\\"\"": unknown
ERROR: for webpack Cannot start service webpack: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/var/lib/docker/volumes/myproject_webpack_assets/_data\\\" to rootfs \\\"/var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697c226dc1d1943762/merged\\\" at \\\"/var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697c226dc1d1943762/merged/srv/myproject/.webpack\\\" caused \\\"mkdir /var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697c226dc1d1943762/merged/srv/myproject/.webpack: read-only file system\\\"\"": unknown
ERROR: for php Cannot start service php: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/var/lib/docker/volumes/myproject_webpack_assets/_data\\\" to rootfs \\\"/var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged\\\" at \\\"/var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged/srv/myproject/.webpack\\\" caused \\\"mkdir /var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged/srv/myproject/.webpack: read-only file system\\\"\"": unknown
How can I get this to work?

Related

How to mount nginx.conf to container in Docker Jenkins?

My Nginx in docker-compose.yml:
...
nginx:
image: nginx:1.19.2-alpine
restart: always
hostname: nginx
ports:
- "9000:9000"
- "9001:9001"
depends_on:
- minio
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
container_name: nginx
...
I use docker compose up -d in terminal and it works fine.
However, when I use docker compose up -d in Jenkins container, it failed to create Nginx container with this error:
ERROR: for nginx Cannot start service nginx: failed to create shim: OCI runtime create failed:
container_linux.go:380: starting container process caused: process_linux.go:545:
container init caused: rootfs_linux.go:75: mounting
"/var/jenkins_home/workspace/workspace/nginx.conf" to rootfs at "/etc/nginx/nginx.conf" 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
Does the error mean Docker want to mount the file inside Jenkins's volume so there's no nginx.conf to mount?
How can I mount my nginx.conf to my Nginx container?
Thanks in advance.
It looks you're executing docker-compose up from a location such your relative path ./nginx.conf is not correct.
This error is typical when docker-compose cannot find source to mount bind-volume.
Assure you're in the correct docker-compose context or try with absolute path instead of ./nginx.conf

How to Mount a file from Host to Container via Docker-Compose

Any I missing something simple here. But Im trying to mount a host file to the container via docker-compose. My docker-compose.yml is:
version: '3.2'
services:
myapp_poller:
restart: unless-stopped
image: &myappImage netenglabs/myapp:0.13.0
container_name: myapp_poller
command: -D /myapp/inventory.yml -k
stdin_open: true
tty: true
volumes:
- "parquet-db:/myapp/parquet"
- "./config/inventory.yml:/myapp/inventory.yml"
- "./config/myapp-cfg.yml:/root/.myapp/myapp-cfg.yml"
entrypoint:
- sq-poller
If I go into ./config and run docker-compose up -d I get:
ERROR: for myapp_poller Cannot start service myapp_poller: OCI runtime create failed: container_linux.go:367: starting container process caused: process_linux.go:495: container init caused: rootfs_linux.go:60: mounting "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-20.04/cc227aed2745c686a488b2a5b99142480733c23c6aa9f72f7d7cb77b4506cee2" to rootfs at "/var/lib/docker/overlay2/8b2cfc582829f784a1a918ba17ef667d2d4c4291b9c0d6655f6f813da486e333/merged/root/.myapp/myapp-cfg.yml" 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
Thanks,

Do I need to create my own nginx.conf file to run this docker-composer.yml file succesfully?

I am trying to get a nextcloud + mariadb + nginx docker-compose up and running locally, but I am stuck when it comes to the nginx.conf file. I am following this guide at the base-fpm section. Here is the docker-compose.yml file, what I ran in my CLI and the error i got:
version: '2'
volumes:
nextcloud:
db:
services:
db:
image: mariadb
restart: always
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=mypw
- MYSQL_PASSWORD=mypw
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app:
image: nextcloud:fpm
restart: always
links:
- db
volumes:
- nextcloud:/var/www/html
environment:
- MYSQL_PASSWORD=mypw
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
web:
image: nginx
restart: always
ports:
- 8080:80
links:
- app
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
volumes_from:
- app
$ docker-compose up
Creating network "nextcloud_default" with the default driver
Creating volume "nextcloud_nextcloud" with default driver
Creating volume "nextcloud_db" with default driver
Creating nextcloud_db_1 ... done
Creating nextcloud_app_1 ... done
Creating nextcloud_web_1 ... error
ERROR: for nextcloud_web_1 Cannot start service web: OCI runtime create failed:
container_linux.go:370: starting container process caused: process_linux.go:459: container init
caused: rootfs_linux.go:59: mounting "/home/nowak/docker/nextcloud/nginx.conf" to rootfs at
"/var/lib/docker/overlay2/4869db7f0302ec8b7e5f4328b861e64627daa78728d443913052cecd1cd095a9/merge
d/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
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:370:
starting container process caused: process_linux.go:459: container init caused:
rootfs_linux.go:59: mounting "/home/nowak/docker/nextcloud/nginx.conf" to rootfs at
"/var/lib/docker/overlay2/4869db7f0302ec8b7e5f4328b861e64627daa78728d443913052cecd1cd095a9/merge
d/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
ERROR: Encountered errors while bringing up the project.
Do I need to create a nginx.conf file and place it in my work directory?
The guide does mention this:
The configuration for nginx is stored in the configuration file nginx.conf, that is mounted into the container. An example can be found in the examples section here.
But when I follow that link, I can't seem to find any example of nginx.conf files.
Looks like other people are also searching for the file, so I'll add the link from my comment to the right file here:
https://github.com/nextcloud/docker/blob/master/.examples/docker-compose/with-nginx-proxy/mariadb/fpm/web/nginx.conf

Cannot bind volume using Windows Docker-Compose

I'm having trouble with a volume in my docker-compose.yml.
docker-compose.yml:
version: "3.3"
services:
prometheus:
image: prom/prometheus:latest
container_name: pg_provi_promentheus
volumes:
- ${PWD}/resources/config/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- pg_provi_prometheus_data:/prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"
# - "-storage.local.path=/prometheus"
ports:
- "9090:9090"
node-exporter:
image: prom/node-exporter:latest
container_name: pg_provi_node_exporter
ports:
- "9100:9100"
grafana:
image: grafana/grafana:latest
container_name: pg_provi_grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_AUTH_ANONYMOUS_ENABLED=true
depends_on:
- prometheus
volumes:
- ${PWD}/resources/config/grafana/provisioning:/etc/grafana/provisioning:ro
- pg_provi_grafana_data:/var/lib/grafana
ports:
- "3000:3000"
volumes:
pg_provi_prometheus_data:
pg_provi_grafana_data:
I constantly get this error message on startup:
[INFO] starting containers
Creating network "pg_provi_default" with the default driver
Creating volume "pg_provi_pg_provi_prometheus_data" with default driver
Creating volume "pg_provi_pg_provi_grafana_data" with default driver
Creating pg_provi_promentheus ... error
Creating pg_provi_node_exporter ... done
ERROR: for pg_provi_promentheus Cannot start service prometheus: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/mnt/c/Entwicklung/home/_workspace/workspace/provinzial-prometheus-grafana/src/main/localhost/pg_provi/resources/config/prometheus.yml\\\" to rootfs \\\"/var/lib/docker/overlay2/643795a7aff240086c1d48371fd7ded76a52d70a53299b01a253c25a529ec0e5/merged\\\" at \\\"/var/lib/docker/overlay2/643795a7aff240086c1d48371fd7ded76a52d70a53299b01a253c25a529ec0e5/merged/etc/prometheus/prometheus.yml\\\" 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 prometheus Cannot start service prometheus: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/mnt/c/Entwicklung/home/_workspace/workspace/provinzial-prometheus-grafana/src/main/localhost/pg_provi/resources/config/prometheus.yml\\\" to rootfs \\\"/var/lib/docker/overlay2/643795a7aff240086c1d48371fd7ded76a52d70a53299b01a253c25a529ec0e5/merged\\\" at \\\"/var/lib/docker/overlay2/643795a7aff240086c1d48371fd7ded76a52d70a53299b01a253c25a529ec0e5/merged/etc/prometheus/prometheus.yml\\\" 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.
Same docker-compose.yml on linux works perfectly fine. I don't get why I cannot mount my prometheus.yml into my container.
Startup and shutdown is straight forward via docker-compose up -d and docker-compose down -v.
Anyone got an idea? Thanks guys.

docker-compose can't load run.sh

I have a docker-compose.yml file that runs a shell script, and has been functioning fine, until all of a sudden it started failing with:
ERROR: for pol_app_1 Cannot start service app: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"run.sh\": executable file not found in $PATH": unknown
ERROR: for app Cannot start service app: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"run.sh\": executable file not found in $PATH": unknown
(I have seen similar questions, but they don't address this specific problem)
The only changes I have been making are to the docker images it uses, but even if I change the image to simply centos:latest docker-compose still fails with the errors above.
My docker-compose.yml file:
version: '3.5'
services:
app:
image: paulhollyer/phoenix:1.4.9
ports:
- 4000:4000
volumes:
- .:/app
depends_on:
- db
command: run.sh
db:
image: paulhollyer/postgres:12
command: 'postgres -c "max_connections=200"'
volumes:
- type: volume
source: postgres-data
target: /var/lib/postgresql/data
volume:
nocopy: true
restart: always
environment:
POSTGRES_PASSWORD: "postgres"
POSTGRES_USER: "postgres"
POSTGRES_DB: "pol_dev"
volumes:
postgres-data:
run.sh is next to docker-compose.yml in the root of the project.
Does anyone know why run.sh can't be found? What could I have done unintentionally to cause this?
Thanks
You must refer to it according to the location it has inside the container. Since the file is in your current host directory and you are adding a volume .:/app that would be /app/run.sh:
command: /app/run.sh
Note to avoid weird problems: If /app happens to be the WORKDIR of the pulled image, command: ./run.sh would also work, but be careful with that. For instance, if that's the case, chances are that /app already has some files in there, and your mapping would be mounting your current host directory on top of them, making them inaccessible.

Resources