volume mongodb with docker-compose - mongodb

I try to turn docker-compose with volume mongodb; But Iget this error and I don't know the origin of this error any idea:
ERROR: for api_db_1 Cannot start service db: OCI runtime create failed: invalid mount {Destination:mongo-data Type:bind Source:/var/lib/docker/volumes/110cc05fb16f8f6381dea1ff6d17e95e4f8458d98e87e9524514653b19db8e6d/_data Options:[rbind]}: mount destination mongo-data not absolute: unknown
I use image mongo:3.6-xenial for mongo and docker-compose version 1.29.2.

I ended up with the same error.
My problem was that I didn't specify the file path in which the volume was set in.
I believe for your case, you have a service called db that uses volumes called mongo-data.
Something like below...
services:
db:
// other service specifications
volumes:
- mongo-data
What I did to solve was to specify the file path docker can look for, similar to this...
services:
db:
// other service specifications
volumes:
- mongo-data:mongo-data-file-path

I'm with the same error here :-(
ERROR: for firebird_db_1 Cannot start service db: failed to create shim: OCI runtime create failed: invalid mount {Destination:storage Type:bind Source:/var/lib/docker/volumes/7d63ff4c2624358a5278b14e08e911077dae3359709bd5e114b25591dbf6e1a0/_data Options:[rbind]}: mount destination storage not absolute: unknown
my docker-compose file is this:
PS.: this docker-compose file was working until a few weeks ago...
version: "3.2"
services:
db:
image: jacobalberty/firebird
volumes:
- ./storage
restart: on-failure
environment:
TZ: America/Sao_Paulo
ISC_PASSWORD: masterkey
FIREBIRD_DATABASE: dev
FIREBIRD_USER: dev
FIREBIRD_PASSWORD: dev
EnableLegacyClientAuth: 'true'
ports:
- 3050:3050

Assign an absolute path for volume mongo-data in docker-compose file should work.

Related

Getting a Docker postgres container to use hosts database files

I have a Postgres database running on my host. The datafiles for the database is stored at /usr/local/var/postgresql#13.
To get the full system running easily I'd like to have a Docker with a Postgres service running for other Docker apps to connect to. I would however like to have the Docker Postgres service to use the existing datafiles on the host ...
How do I set up the volume correctly to point to the hosts database files?
Do have to have a user/password when running the Docker against existing datafiles?
I have the following but can get the volume to work ...
version: "3.9"
services:
web:
build: .
ports:
- 8081:3011
depends_on:
- db
environment:
- PGHOST=db
- PGDATABASE=loggingtestdb
- PGUSER=postgres
- PGPASSWORD=postgres
db:
image: postgres
ports:
- 5432:5432
volumes:
- /usr/local/var/postgresql#13 <--- Need help here.
How do I map the container pg datafile location to the hosts pg datafile location? 🙏
Update 1
This is the datafile folder for the db on the host
After comments I updated the volumes to below
volumes:
- /usr/local/var/postgresql#13:/var/lib/postgresql/data
But when running docker compose I only get
Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /usr/local/var/postgresql#13
Update 2
/use/local works fine. But as soon as I add the /var folder to the path Docker for some reason can’t find it … What am I missing here?

Docker-compose.yml problems of configuraion

I'm a french dev...
I have a problem with the config file docker-compose.yml...
When i enter docker-compose up they show me:
Pulling db (postgresql:9.4)...
ERROR: The image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing.
Continue with the new image? [yN]y
Pulling db (postgresql:9.4)...
ERROR: pull access denied for postgresql, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
my docker-compose.yml:
version: '3'
services:
hello-world:
build: .
command: npm run dev
ports:
- "3000:8080"
env_file:
- database.env
db:
image: postgresql:9.4
ports:
- "5432:8080"
env_file:
- database.env
Please if someone can help me...
You have a typo in the image name. It should be postgres:9.4 not postgresql:9.4

Permission denied when running `mkdir` inside of a Docker container

I am using Docker Compose to run several containers, including one with a Postgres image. I am attempting to add a volume to that container to persist my data across container builds. However, I am receiving an error when it tries to create a directory for this volume within the container.
I run:
docker-compose build
then
docker-compose up
And I receive the following error:
ERROR: for cxbenchmark_db_1 Cannot start service db: oci runtime error: container_linux.go:265: starting container process caused "process_linux.go:368: container init caused \"rootfs_linux.go:57: mounting \\"/var/lib/docker/volumes/69845a017b4465e9122852a75ca194db473df95fa218658b8a60fb56eba9be9e/_data\\" to rootfs \\"/var/lib/docker/overlay2/627956d63fb0480448079577a83b0b54f83866fdf31136b7c669541c3f672355/merged\\" at \\"/var/lib/docker/overlay2/627956d63fb0480448079577a83b0b54f83866fdf31136b7c669541c3f672355/merged/var/lib/postgresql/data\\" caused \\"mkdir /var/lib/docker/overlay2/627956d63fb0480448079577a83b0b54f83866fdf31136b7c669541c3f672355/merged/var/lib/postgresql/data: permission denied\\"\""
My full docker-compose.yml looks like this (note the service called db where the volume is defined):
version: '3'
services:
nginx:
image: nginx:latest
ports:
- 80:8000
volumes:
- ./src:/src
- ./config/nginx:/etc/nginx/conf.d
- ./src/static:/static
depends_on:
- web
web:
build: .
command: bash -c "python manage.py makemigrations && python manage.py migrate && gunicorn cx_benchmark.wsgi -b 0.0.0.0:8000"
depends_on:
- db
volumes:
- ./src:/src
- ./src/static:/static
expose:
- 8000
db:
image: postgres:latest
volumes:
- /private/var/lib/postgresql:/var/lib/postgresql
ports:
- 5432:5432
Any ideas for how to solve?
The error you are seeing is not a problem (necessarily) with the explicit volume bind mount in your compose file, but rather with the VOLUME declaration in the main postgres official Docker image Dockerfile:
VOLUME /var/lib/postgresql/data
Since you haven't provided a mount-point for this directory (but rather the parent), the docker engine is creating a local volume and then trying to mount that volume into your already bind-mounted location and getting a permissions error.
For clarity, here is the volume the docker engine created for you:
/var/lib/docker/volumes/69845a017b4465e9122852a75ca194db473df95fa218658b8a60fb56eba9be9e/_data
And here is the directory location at which it is trying to bind mount that dir; on top of your bind mount from /private/var/lib/postgresql:
mkdir /var/lib/docker/overlay2/627956d63fb0480448079577a83b0b54f83866fdf31136b7c669541c3f672355/merged/var/lib/postgresql/data: permission denied
Now, I think the reason this is failing is that you may have turned on user namespaces in your Docker engine ("userns-remap" flag/setting) such that the container doesn't have permissions to create a directory in that root-owned location on your host. Barring that, the only other option is that the postgres container is starting as a non-root user, but I don't see anything in your compose file or the official Dockerfile for the latest release that uses the USER directive.
As an aside, since you are ending up with double-volumes because your bind mount doesn't match the VOLUME specifier in the postgres Dockerfile, you could change your compose file to mount to /var/lib/postgresql/data and get around that extra volume being created. Especially if you expect your DB data to end up in /private/var/lib/postgresql, as it may be surprising to find it isn't there, but rather in the /var/lib/docker/volumes/.. location.

How to compose an external data directory in PostgreSQL image within Docker?

I'm trying to create a couple of containers with Docker. One is a postgres:latest image and the other is ubuntu:latest image with postgresql-client installed.
I have an existing database cluster in my localhost that I've used before install docker, of course. Now I want to use that cluster in my PostgreSQL container. The path in my computer is /Users/Marco/Data.
I've created a volume too, with the command docker volume create --opt device=/Users/Marco/Data data_container to store the cluster in it.
Then tried to make a docker-compose.ymlfile with the following content:
version: '2'
services:
db:
image: postgres
environment:
- PGDATA=/var/lib/postgresql/data/
ports:
- "5432:5432"
volumes:
- data_container:/var/lib/postgresql/data/pgdata
shell:
image: ubuntu_pgsql
command: /bin/bash
tty: true
stdin_open: true
links:
- db
volumes:
data_container:
external: true
When I want to launch the containers with docker-compose up -d it shows me the following error:
ERROR: for db Cannot start service db: error while mounting volume '/var/lib/docker/volumes/data_container/_data': error while mounting volume with options: type='' device='/Users/Marco/Data' o='': no such device
ERROR: Encountered errors while bringing up the project.
What could be failing? Thanks.
If data container is a directory you should declare as:
volumes:
- ./data_container:/var/lib/postgresql/data/pgdata
If you used a data_container without ./ before, docker compose understand that is a file, not a directory.

docker-compose postgresql persitent local storage

How can I setup postgresql in docker to be persistent into a local folder?
version: '2'
services:
db:
image: postgres:9.6.1-alpine
ports:
- "5432:5432"
environment:
- POSTGRES_USER=a
- POSTGRES_PASSWORD=a
- POSTGRES_DB=a
volumes:
- /var/lib/postgresql:./postgres
volumes:
pgdata:
driver: local
This will not work and yield only
ERROR: for db Cannot create container for service db: invalid volume spec "postgres": invalid volume specification: 'postgres': invalid mount config for type "volume": invalid mount path: 'postgres' mount path must be absolute
ERROR: Encountered errors while bringing up the project.
You need to use absolute mount path, ./postgres should be changed.