Docker Compose GPU Support: services.*.deploy.resources.reservations Additional property devices is not allowed - docker-compose

Versions of Docker tooling:
Docker Compose version v2.6.0
Docker Engine Version 20.10.17 (client)
Docker Engine Version 20.10.17 (server)
I've got a compose file that starts a swarm with networks and secrets, so I'm using Docker Compose File Version 3.9.
One of my services is a GPU resource, so I added this based on current docs:
version: "3.9"
services:
my-app:
image: my-app:latest
deploy:
resources:
reservations:
devices:
- capabilities: [gpu]
count: all
. . .
My IDE is complaining with "expected scalar value" indicating that it doesn't recognize the key or value of capabilities and count and when I run the command:
docker stack deploy --compose-file docker-compose.yml my-stack
Docker throws an error:
services.prosit-app.deploy.resources.reservations Additional property devices is not allowed
Based on the versions of my Docker tools and the schema I'm using, this should all work (I think). What am missing?
I've tried various file versions and I can get the IDE warning to go away but then Docker can't support the file version. I've tried with and without quotes ["gpu"], different options, etc, to no avail.

This question was asked already (my bad) and the answer was missed by me and others:
Docker Compose returns error about property devices when trying to enable GPU
Reference:
https://docs.docker.com/compose/compose-file/compose-file-v3/#devices

Related

Docker compose equivalent of `docker run --gpu=all` option

To automate the configuration (docker run arguments) used to launch a docker container, I am writing a docker-compose.yml file.
My container should have access to the GPU, and so I currently use docker run --gpus=all parameter. This is described in the Expose GPUs for use docs:
Include the --gpus flag when you start a container to access GPU
resources. Specify how many GPUs to use. For example:
$ docker run -it --rm --gpus all ubuntu nvidia-smi
Unfortunately, Enabling GPU access with Compose doesn't describe this use case exactly. This guide uses the deploy yaml element, but in the context of reserving machines with GPUs. In fact, another documentation says that it will be ignored by docker-compose:
This only takes effect when deploying to a swarm with docker stack deploy, and is ignored by docker-compose up and docker-compose run.
After trying it and solving a myriad of problems along the way, I have realized that it is simply the documentation that is out of date.
Adding the following yaml block to my docker-compose.yml resulted in nvidia-smi being available to use.
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]

Docker Compose - invalid variable

I have docker compose yml file in my project file.
When try to run the below commend i get the below error.
docker-compose up
I get the below error message
invalid variable name "docker-compose.yml"
I have installed and uninstalled docker multiple times.
my Docker version - Docker version 20.10.8, build 3967b7d
my docker-compose version - Docker Compose version v2.0.0-rc.3
Check that your environment variables or .env file does not contain multiline variables (e.g. SSH keys). After flattening them, error should disappear. Source: https://github.com/Azure/aci-deploy/issues/29

Does docker-compose version 1.29.1 support the --gpus parameter?

Does docker-compose version 1.29.1 support the --gpus parameter? If not, are there other parameters that support setting up the use of gpu in docker-compose 1.29.1 ?
--gpus argument works with docker command. For docker-compose GPU configuration is done within docker-compose.yml:
Using the runtime option (legacy v2.3 format)
version: "2.3"
services:
test:
image: nvidia/cuda:10.2-base
command: nvidia-smi
runtime: nvidia # <- this option
Using the device structure (since docker-compose v1.28.0)
version: "3.8"
services:
test:
image: nvidia/cuda:10.2-base
command: nvidia-smi
deploy:
resources:
reservations:
devices:
- driver: nvidia
# that's the closest analogue to --gpus; provide
# an integer amount of devices or 'all'
count: 1
# Devices are reserved using a list of capabilities, making
# capabilities the only required field. A device MUST
# satisfy all the requested capabilities for a successful
# reservation.
capabilities: [gpu]
The latter might seem a bit complicated but there is a guide the explains both (Enabling GPU access with Compose
) and some extra information can be obtained from The Compose Specification.

docker-compose: Not accepting extensions starting with "x-" (Invalid top-level property "x-...")

I'm trying to deploy a service which uses docker-compose files and I've been seeing the following error:
Invalid top-level property "x-...". Valid top-level sections for this Compose file are: secrets, version, volumes, services, configs, networks, and extensions starting with "x-".
You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions ...
I reproduced the error using this simple docker-compose.yml file:
version: "3.5"
x-secrets: &secrets
secrets:
- foo
services:
a:
<<: *secrets
image: a-image
secrets:
foo:
external: true
The command
docker-compose -f docker-compose.yml up
Gives the following output:
ERROR: The Compose file './docker-compose.yml' is invalid because:
Invalid top-level property "x-secrets". Valid top-level sections for this Compose file are: secrets, version, volumes, services, configs, networks, and extensions starting with "x-".
You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
Versions:
docker --version
Docker version 19.03.6, build 369ce74a3c
docker-compose --version
docker-compose version 1.17.1, build unknown
Running on Ubuntu 18.04.
Thanks for any input!
Resolved this by upgrading docker-compose to
docker-compose version 1.27.4, build 40524192
This means that either the format of your docker-compose.yml file is not correct or your version of docker-compose is too old.
It's always a good practice to upgrade to the latest version of docker-compose - you can do it like this:
Get the latest version
VERSION=$(curl https://api.github.com/repos/docker/compose/releases/latest | jq .name -r)
Install it
sudo curl -L "https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Give system permissions
sudo chmod +x /usr/local/bin/docker-compose
Logout, then login again
Now that you have the latest version, check if the format of your docker-compose.yml file is correct by comparing it to the examples in the official documentation (again, check the format for the latest version). Note that small things like single- vs double-space and different special characters matter a lot!

Docker compose - secrets Additional property secrets is not allowed

docker-compose --version
docker-compose version 1.11.1, build 7c5d5e4
I have secret 'my_secret_data' added to my swarm cluster:
The start of my compose file looks like:
version: "3.1"
secrets:
my_secret_data:
external: true
services:
master:
image: jenkins-master
secrets:
- my_secret_data
ports:
- "8080:8080"
- "50000:50000"
'docker stack deploy' continually gives the error:
secrets Additional property secrets is not allowed
I have followed how do you manage secret values with docker-compose v3.1? to the letter as far as I can tell and have the correct versions installed but keep getting the above error. Any help greatly appreciated.
Change compose file version to latest version.
In short, version '3' is not resolved to the latest '3.x' version. Find what the latest version is here https://docs.docker.com/compose/compose-file/#compose-and-docker-compatibility-matrix
The "Additional property secrets is not allowed" error can be caused either by:
running Docker Engine < 1.13.1, or
using a compose file version number < '3.1' in a docker-compose file such as docker-compose.yml or docker-cloud.yml
If you are experiencing this problem confirm that both are correct.
This also applies to other Docker interfaces and tools.
For examples, in Portainer, yml with secrets lines pasted into the Create Stack dialog should begin with the line version: '3.1' or you will encounter the same error -- even with an up-to-date Docker Engine 1.13.1+.
In my case, Service: had an extra tab prior. Moment I removed tab prior to it, it worked.