Docker secrets not accounting for remote context - docker-compose

I am using docker contexts to deploy an application (3 containers ... web/postgres/nginx) from Windows 10 to a remote Ubuntu 20.04 server using a 3.8 docker-compose.yml file. The remote context is type moby and the endpoint is ssh://swright#xxx.xxxxxx.xxx. The orchestrator is swarm but I have not implemented that.
Everything worked perfectly until I added secrets. The web container now can't be created because it says I have an invalid mount path ('C:/run/secrets/secret_key.txt' mount path must be absolute).
Creating plantweb ... error
ERROR: for plantweb Cannot create container for service web: invalid mount config for type "bind": invalid mount path: 'C:/run/secrets/secret_key.txt' mount path must be absolute
That it is looking for the secret file on C: tells me it is trying to mount a local Windows file when it should be mounting the /run/secrets/secret_key.txt file I created on the remote.
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-67-generic x86_64)Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-67-generic x86_64)
...
Last login: Wed Mar 24 17:59:40 2021 from 70.51.98.164
swright#ubuntu2:~$ cd /run/secrets
swright#ubuntu2:/run/secrets$ ls
plant_api_key.txt secret_key.txt sendgrid_api_key.txt sendgrid_default_from_email.txt sql_password.txt sql_user.txt
swright#ubuntu2:/run/secrets$
I believe I've done exactly what is described in the docker documentation regarding secrets. Could there be a bug in docker that secrets don't respect the context I'm in? Or have I done something wrong?
This is my yml file.
version: '3.8'
services:
web:
container_name: plantweb
restart: always
build: ./django-plants/
volumes:
- static_volume:/usr/src/app/static
- media_volume:/usr/src/app/media
secrets:
- secret_key
- sql_user
- sql_password
- plant_api_key
- sendgrid_api_key
- sendgrid_default_from_email
env_file:
- ./.env.prod
expose:
- 8000
networks:
- nginx_network
- plants_network
depends_on:
- db
<snip ...>
secrets:
secret_key:
file: /run/secrets/secret_key.txt
sql_user:
file: /run/secrets/sql_user.txt
sql_password:
file: /run/secrets/sql_password.txt
plant_api_key:
file: /run/secrets/plant_api_key.txt
sendgrid_api_key:
file: /run/secrets/sendgrid_api_key.txt
sendgrid_default_from_email:
file: /run/secrets/sendgrid_default_from_email.txt
docker-compose config returns this, no matter what context I'm using (local or remote).
<snip>
secrets:
plant_api_key:
file: C:\run\secrets\plant_api_key.txt
secret_key:
file: C:\run\secrets\secret_key.txt
sendgrid_api_key:
file: C:\run\secrets\sendgrid_api_key.txt
sendgrid_default_from_email:
file: C:\run\secrets\sendgrid_default_from_email.txt
sql_password:
file: C:\run\secrets\sql_password.txt
sql_user:
file: C:\run\secrets\sql_user.txt
<snip>

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?

volume mongodb with docker-compose

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.

Declare volumes in docker compose

I am using docker-compose file generated by docker-app
docker-app render | docker-compose -f - up
The docker app file looks like this and it works as expected. But I am not able to use volumes.
I use -v parameter while using docker run command like this...
-v /my/custom3399:/etc/mysql/conf.d
-v /storage/mysql/datadir3399:/var/lib/mysql
How do I declare volumes in compose file?
# vi hello.dockerapp
# This section contains your application metadata.
# Version of the application
version: 0.1.0
# Name of the application
name: hello
# A short description of the application
description:
# Namespace to use when pushing to a registry. This is typically your Hub username.
#namespace: myHubUsername
# List of application maitainers with name and email for each
maintainers:
- name: root
email:
# Specify false here if your application doesn't support Swarm or Kubernetes
targets:
swarm: false
kubernetes: false
--
# This section contains the Compose file that describes your application services.
version: "3.5"
services:
mysql:
image: ${mysql.image.version}
environment:
MYSQL_ROOT_PASSWORD: india${mysql.port}
ports:
- "${mysql.port}:3306"
--
# This section contains the default values for your application settings.
mysql.image.version: shantanuo/mysql:5.7
mysql.port: 3391
update:
The script mentioned above works well. But once I add volumes, I get an error:
version: "3.5"
services:
mysql:
image: ${mysql.image.version}
environment:
MYSQL_ROOT_PASSWORD: india${mysql.port}
ports:
- "${mysql.port}:3306"
volumes:
- type: volume
source: mysql_data
target: /var/lib/mysql
volumes:
mysql_data:
external: true
And the error is:
docker-app render | docker-compose -f - up
Recreating e5c833e2187d_hashi_mysql_1 ... error
ERROR: for e5c833e2187d_hashi_mysql_1 Cannot create container for service mysql: Duplicate mount point: /var/lib/mysql
ERROR: for mysql Cannot create container for service mysql: Duplicate mount point: /var/lib/mysql
ERROR: Encountered errors while bringing up the project.
As mentioned in the comment, the rendered output is as follows:
# /usr/local/bin/docker-app render
version: "3.5"
services:
mysql:
environment:
MYSQL_ROOT_PASSWORD: india3391
image: shantanuo/mysql:5.7
ports:
- mode: ingress
target: 3306
published: 3391
protocol: tcp
volumes:
- type: volume
source: mysql_data
target: /var/lib/mysql
volumes:
mysql_data:
name: mysql_data
external: true
This issue was resolved once I changed the directory name.
# cd ..
# mv hashi/ hashi123/
# cd hashi123
Not sure how this worked. But since I am able to start the server stack, I am posting it as answer.

Docker Compose Mounting Volume Error: No Such File or Directory

I am trying to build a simple Drupal container using docker-compose, but I'm getting an error when trying to mount the named volume. Here is my docker-compose.yml file:
version: '2.1'
services:
web:
build: ./build
image: "myrmidon16/drupal-base:latest"
working_dir: "/var/www/html"
volumes:
- sites:/var/www/html/sites
links:
- "db"
ports:
- 8001:80
db:
image: "mysql:latest"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=root
- MYSQL_PASSWORD=root
- MYSQL_DATABASE=drupal-base
volumes:
- ".:/var/www/html"
ports:
- "3306"
drush:
image: "mparker17/mush"
working_dir: "/var/www/html"
volumes:
- .:/var/www/html
links:
- "db"
volumes:
sites:
driver: local
driver_opts:
type: bind
o: bind
device: ${PWD}/sites
But when I run docker-compose up -d I get the following error, even though the directory exists:
ERROR: for web Cannot create container for service web: error while mounting volume with options: type='bind' device='/mnt/f/Documents/sites' o='bind': no such file or directory
I'm running Docker for Windows Edge (18.05.0-ce-rc1) on Windows 10 Pro with Compose v 1.21.0. I'm also sharing the F drive through Docker for Windows.
Please let me know if you need any additonal information. Thank you.
On Windows, local driver does not support any options.
So in your docker-compose options o:bind is invalid.
According to: Documentation https://docs.docker.com/engine/reference/commandline/volume_create/#driver-specific-options
It does work on Windows, but you have to add a leading slash to the device option, e.g.
docker volume create \
--opt type=none \
--opt o=bind \
--opt device=/$(pwd)/grafana/dashboards \
--name grafana_dashboards
On Windows you should not create volume in the volume section. The one in service is enough to create a mounth to the Windows file system, as long as it is enabled in:
Docker->Settings->Shared Drives - the whole drive
and make sure you click the "Reset credentials" if you change windows password
The path c:\Temp\some_dir works and the current directory notation(.) I am not sure.

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.