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

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!

Related

Can you access file in another containerd but same pod? [duplicate]

Is it possible with Docker to combine two images into one?
Like this here:
genericA --
\
---> specificAB
/
genericB --
For example there's an image for Java and an image for MySQL.
I'd like to have an image with Java and MySQL.
No, you can only inherit from one image.
You probably don't want Java and MySQL in the same image as it's more idiomatic to have a single component in a container i.e. create a separate MySQL container and link it to the Java container rather than put both into the same container.
However, if you really must have them in the same image, write a Dockerfile with Java as the base image (FROM statement) and install MySQL in the Dockerfile. You should be able to largely copy the statements from the official MySQL Dockerfile.
Docker doesn't directly support this, but you can use DockerMake (full disclosure: I wrote it) to manage this sort of "inheritance". It uses a YAML file to set up the individual pieces of the image, then drives the build by generating the appropriate Dockerfiles.
Here's how you would build this slightly more complicated example:
--> genericA --
/ \
debian:jessie --> customBase ---> specificAB
\ /
--> genericB --
You would use this DockerMake.yml file:
specificAB:
requires:
- genericA
- genericB
genericA:
requires:
- customBase
build_directory: [some local directory]
build: |
#Dockerfile commands go here, such as
ADD installA.sh
RUN ./installA.sh
genericB:
requires:
- customBase
build: |
#Here are some other commands you could run
RUN apt-get install -y genericB
ENV PATH=$PATH:something
customBase:
FROM: debian:jessie
build: |
RUN apt-get update && apt-get install -y buildessentials
After installing the docker-make CLI tool (pip install dockermake), you can then build the specificAB image just by running
docker-make specificAB
If you do docker commit, it is not handy to see what commands were used in order to build your container, you have to issue a docker history image
If you have a Dockerfile, just look at it and you see how it was built and what it contains.
Docker commit is 'by hand', so prone to errors, docker build using a Dockerfile that works is much better.
You can put multiple FROM commands in a single Dockerfile.
https://docs.docker.com/reference/builder/#from

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

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

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

stack name with docker-compose

Is there a way to set the stack name when using docker-compose?
Currently it takes the folder name (which is a horrible area) and that leads to some confusion.
For example, we have several projects that have a database folder that contains the database stack. When running these on a single host, we have now several database stacks.
There are several ways to do it:
1. Using --project-name (or -p) option when calling docker-compose:
docker-compose -p "my-app" up
Caution: -p "my-app" must come before up.
2. COMPOSE_PROJECT_NAME environment variable:
export COMPOSE_PROJECT_NAME=my-app
docker-compose up
3. COMPOSE_PROJECT_NAME in .env file
Create a file named .env in the project root and set the COMPOSE_PROJECT_NAME environment variable there:
COMPOSE_PROJECT_NAME=some_app
and then:
docker-compose up
The .env file is read from the folder where the docker-compose command
is executed, NOT from the folder of the docker-compose.yml file.
Assuming the following project structure:
root
- database
- docker-compose.yml
- .env
- app
- docker-compose.yml
- .env
- ...
The command below, executed in the root folder, will not give desired effects:
# Stack name 'database' (the folder name). The root/database/.env file not read.
docker-compose -f ./database/docker-compose.yml up
The docker-compose command needs to be executed in the root/database folder:
# Stack name from the root/database/.env
cd database
docker-compose up
If you use option 2 or 3, the project name is applied to all docker-compose commands, as if it were specified with the -p option.
It looks like the project name can be set using the name top level element in the docker-compose file as described here: https://docs.docker.com/compose/compose-file/#name-top-level-element
Top-level name property is defined by the specification as project name to be used if user doesn’t set one explicitly. Compose implementations MUST offer a way for user to override this name, and SHOULD define a mechanism to compute a default project name, to be used if the top-level name element is not set.
This doesn't seem to be well documented anywhere else, and I didn't see a reference to it in the spec changelog, so I'm not sure if this has always been part of the spec, or if compose just didn't support it until recently.
Example
My current directory (pwd):
/Users/brahmlower/development/compose-test
My compose file (cat docker-compose.yml):
version: "3.8"
name: my-project
services:
hello-world:
image: "hello-world:latest"
Without the name property, we would expect to see the stack started with the prefix compose-test since that's the name of the directory. However when I bring the stack up, we see compose names the stack my-project as expected.
The stack output (docker compose up -d):
[+] Running 2/2
⠿ Network my-project_default Created
⠿ Container my-project-hello-world-1 Started
Versions
In case it's helpful, my docker versions are:
compose (docker compose version):
Docker Compose version v2.10.2
docker (docker version):
Client:
Cloud integration: v1.0.29
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:04:45 2022
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Desktop 4.12.0 (85629)
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:01:01 2022
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0

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.