Version in "./docker-compose.yml" is unsupported - docker

I have the following docker-compose.yml file
services:
containerA:
healthcheck:
test: "/build/docheck"
interval: "10s"
hostname: "containerA"
container_name: "containerA"
build:
dockerfile: "Dockerfile-5.6"
ports:
- "8081:8081"
version: "2.1"
When I try the following command: docker-compose up
it fails due to:
ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") 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/
I have the following setting:
$> docker-compose --version
docker-compose version 1.8.0, build unknown
$> docker --version
Docker version 17.12.0-ce, build c97c6d6
$> uname -r
4.9.0-4-amd64
$> lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 9.3 (stretch)
Release: 9.3
Codename: stretch
I need to use version 2.1 because I am using the healthcheck. Any ideas why this is complaining?

adding this because i ran into the same error on Ubuntu.
For me, it had nothing to do with my Compose version despite what the error message says; i just had to run with sudo. so
sudo docker-compose up

Compose files Version 2.1 are supported by Docker Compose version 1.9.0+. And you have docker-compose version 1.8.0. To upgrade docker-compose you can run following commands:
If installed via apt-get:
sudo apt-get remove docker-compose
If installed via curl:
sudo rm /usr/local/bin/docker-compose
If installed via pip:
pip uninstall docker-compose
Then find the newest version on the release page at GitHub or by curling the API and extracting the version from the response using grep:
VERSION=$(curl --silent https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d')
Finally, download to your $PATH-accessible location and set permissions:
DESTINATION=/usr/bin/docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m) -o $DESTINATION
sudo chmod 755 $DESTINATION

Following the link to details about versions, you'll find:
Version 2.1
An upgrade of version 2 that introduces new parameters only available
with Docker Engine version 1.12.0+. Version 2.1 files are supported by
Compose 1.9.0+.
https://docs.docker.com/compose/compose-file/compose-versioning/#version-21
You'll need to upgrade your docker-compose install to support the 2.1 file version. https://docs.docker.com/compose/install/

I was getting this error when I was trying the command docker-compose up with the docker compose version 3. Then I run the command to check the docker version docker version, which result the below output.
PS C:\SVenu\M4Movie\Api\Api> docker version
Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:12:48 2018
OS/Arch: windows/amd64
Experimental: false
Orchestrator: swarm
So my version is 18.03, which is the latest one for now. So I moved to this link to check the compose file version which supports this engine. Then changed my docker compose version to 3.6.
version: '3.6'
Everything was working fine after that.

Installation of a new version of Docker Compose helped me to fix this error. See official documentation.

Related

WORKDIR doesn't work when running docker-compose run on Windows

It looks like the WORKDIR inside my Dockerfile doesn't work. I'm trying this on Windows 10. The same works perfectly on Mac.
Here are my project files:
docker-compose.yml:
version: '3'
services:
php_under_test:
build: tests/DockerImages/${PHP_VERSION}
volumes:
- .:/opt/project/phpstorm-stubs
test_runner:
build: tests/DockerImages/testRunner
volumes:
- .:/opt/project/phpstorm-stubs
The tests/DockerImages/testRunner folder has only this Dockerfile:
FROM php:8.1-apache
RUN echo 'memory_limit = 1024M' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN apt-get update && apt-get -y install git zip unzip
WORKDIR /opt/project/phpstorm-stubs
If I run docker-compose -f docker-compose.yml run test_runner /usr/local/bin/php tests/Tools/generate-stub-map in cmd.exe in the same directory where docker-compose.yml lies, I would get:
C:\Projects\phpstorm-stubs>docker-compose -f docker-compose.yml run test_runner /usr/local/bin/php tests/Tools/generate-stub-map
WARNING: The PHP_VERSION variable is not set. Defaulting to a blank string.
Creating phpstorm-stubs_test_runner_run ... done
Could not open input file: tests/Tools/generate-stub-map
ERROR: 1
However, if I run the same using -w: docker-compose -f docker-compose.yml run -w /opt/project/phpstorm-stubs test_runner /usr/local/bin/php tests/Tools/generate-stub-map - that would work. Output:
C:\Projects\phpstorm-stubs>docker-compose -f docker-compose.yml run -w /opt/project/phpstorm-stubs test_runner /usr/local/bin/php tests/Tools/generate-stub-map
WARNING: The PHP_VERSION variable is not set. Defaulting to a blank string.
Creating phpstorm-stubs_test_runner_run ... done
Parsing "/opt/project/phpstorm-stubs/tests/Tools/../../aerospike/aerospike.php"
Parsing "/opt/project/phpstorm-stubs/tests/Tools/../../aerospike/Bytes.php"
etc...
I can see here that -w is outdated and I should use --project-directory instead, but doesn't work also:
C:\Projects\phpstorm-stubs>docker-compose -f docker-compose.yml --project-directory /opt/project/phpstorm-stubs run test_runner /usr/local/bin/php
tests/Tools/generate-stub-map
WARNING: The PHP_VERSION variable is not set. Defaulting to a blank string.
ERROR: build path C:\opt\project\phpstorm-stubs\tests\DockerImages either does not exist, is not accessible, or is not a valid URL.
I've tried to look for something related at docker/compose github issues but found none.
docker version output:
Client:
Cloud integration: v1.0.24
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:09:02 2022
OS/Arch: windows/amd64
Context: default
Experimental: true
Server: Docker Desktop 4.10.1 (82475)
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:23 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.6
GitCommit: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc:
Version: 1.1.2
GitCommit: v1.1.2-0-ga916309
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Any help with this is much appreciated.
Sounds like you built test_runner image once using Dockerfile of previous version without WORKDIR parameter and trying to re-run container using this outdated image.
You have to remove image manually or force rebuild it using docker-compose build (or docker-compose up --build) instead of docker-compose run
Also this link may be helpfull
WORKDIR from dockerfile corresponds to working_dir in compose file https://docs.docker.com/compose/compose-file/#working_dir
Try to use
test_runner:
build: tests/DockerImages/testRunner
working_dir: /opt/project/phpstorm-stubs
volumes:
- .:/opt/project/phpstorm-stubs
You have to understand the different path of your whole project.
Location of your docker file C:\Projects\phpstorm-stubs\
Location of base of your project /opt/project/phpstorm-stubs so the exact whole path to your project base in reality is C:\Projects\phpstorm-stubs\opt\project\phpstorm-stubs and so the files it is trying to find is actually at C:\Projects\phpstorm-stubs\opt\project\phpstorm-stubs\usr\local\bin\php tests\Tools\generate-stub-map
So once you used the -f docker-compose.yml it by default thinks that your whole project is at C:\Projects\phpstorm-stubs\ but when you use it with -w /opt/project/phpstorm-stubs it knows that base of your project path is here so it knows that tests/Tools/generate-stub-map is further ahead of it.
And lastly --project-directory requires the whole path from the base of current drive
To sum up my answer you need to use command
docker-compose -f docker-compose.yml --project-directory /Projects/phpstorm-stubs/opt/project/phpstorm-stubs run test_runner /usr/local/bin/php tests/Tools/generate-stub-map

Error response from daemon: Dockerfile parse error Unknown flag: mount

There is a previous question (Docker Unknown flag --mount) facing the same error that was due to having an out-of-date version of Docker running. I have an up-to-date version of Docker running.
I have the following Dockerfile:
FROM continuumio/miniconda3
RUN --mount=type=ssh pip install git+ssh://git#github.com/myrepo/myproject.git#develop
RUN conda install numpy
...
According to the documentation, I should be able to simply run docker build --ssh default .. However, I receive the following error:
Sending build context to Docker daemon 2.048kB
Error response from daemon: Dockerfile parse error line 3: Unknown flag: mount
Output of docker version:
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:39 2019
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:06 2019
OS/Arch: linux/amd64
Experimental: true
I would like to build a Docker image without exposing my private SSH credentials, and this seemed to be the supported method. Anyone have thoughts on what's causing the issue?
tl;dr
Dockerfile
# syntax=docker/dockerfile:experimental
FROM continuumio/miniconda3
RUN --mount=type=ssh pip install git+ssh://git#github.com/myrepo/myproject.git#develop
RUN conda install numpy
...
Note: the comment on the first line is required voodoo
Then build your docker image with:
DOCKER_BUILDKIT=1 docker build --ssh default -t my_image .
With this, you will be able to use the --mount option for the RUN directive in your Dockerfile.
Long answer
As found in the documentation here, ssh forwarding when building docker image is enabled only when using the BuildKit backend:
External implementation features
This feature is only available when using the
BuildKit
backend.
Docker build supports experimental features like cache mounts, build
secrets and ssh forwarding that are enabled by using an external
implementation of the builder with a syntax directive. To learn about
these features, refer to the documentation in BuildKit
repository.
For this you need Docker 18.09 (or later) and you also need to run the docker build command with the DOCKER_BUILDKIT=1 environment variable and start your Docker file with the following magic comment : # syntax=docker/dockerfile:experimental.
Also you can edit /etc/docker/daemon.json and add :
{
"experimental" : false,
"debug" : true,
"features": {
"buildkit" : true
}
}
If you are using sudo for docker commands, you might need:
sudo DOCKER_BUILDKIT=1 ...
To anyone out there that might be struggling with this sort of error: ensure that the first line of the file is '# syntax=docker/dockerfile:experimental'. This will work:
# syntax=docker/dockerfile:experimental
FROM golang:1.14.1 as builder
...
RUN --mount=type=ssh GOSUMDB=off go get -d -v ./...
BUT if you add a comment at the start of the file like so:
# SOME SILLY COMMENT HERE <--- this ostensibly innocent comment ruins everything!
# syntax=docker/dockerfile:experimental
FROM golang:1.14.1 as builder
...
RUN --mount=type=ssh GOSUMDB=off go get -d -v ./...
Then 'syntax=...' will not be taken into account because it's no longer on the very first line. This is why you get that weird error about 'mount' below! Gah!
Hopefully this will save a few hours from the lives of a few people.
The error message that you are getting due to writing --mount inside the Dockerfile. You have to enable Docker BuildKit first in order to use this syntax.
You can check all of the currently available build options through here
Locally I just needed DOCKER_BUILDKIT=1 docker build...
In TeamCity build pipeline my docker file still needed the magic line to overcome this issue. My TeamCity agent is running Docker version 19.03.9
So in 2022 this is still my conclusion:
Try the magic line mentioned at the top of your Docker file:
#syntax=docker/dockerfile:experimental
Use BUILDKIT. e.g. DOCKER_BUILDKIT=1
.. and in my context this is all for running the following line:
RUN --mount=type=ssh npm install "git+ssh://git#github.com:dra_____.git"
Maybe this will save some folks some time.

CircleCI './docker-compose.yml' service 'version' doesn't have any configuration options

Related, but not duplicated: Docker - docker-compose 'version' doesn't have any configuration options
I am currently using a v2 docker-compose.yml with the following circle.yml:
machine:
services:
- docker
test:
post:
- docker build --rm=false -t zurfyx/repo:$CIRCLE_SHA1 .
- docker-compose run web npm test
deployment:
hub:
branch: master
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
- docker push zurfyx/repo:$CIRCLE_SHA1
CircleCI gives the following output:
docker-compose run web npm test
ERROR: In file './docker-compose.yml' service 'version' doesn't have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.
docker-compose run web npm test returned exit code 1
I tried the following solutions that show up on a very recent CircleCI forum post, but I didn't manage to get rid of the problem.
Upgrading both docker and docker-compose to the latest version is required:
machine:
pre:
- curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0
- pip install --upgrade pip
- pip install docker-compose
services:
- docker
Why both?
Some say that upgrading docker-compose to the latest version by using pip is enough, but apparently is not (because the current Docker Engine CircleCI version does not support it, at least not anymore):
ERROR: The Docker Engine version is less than the minimum required by
Compose. Your current project requires a Docker Engine of version
1.10.0 or greater.
If you just upgrade Docker engine, it does not make any difference, since a higher docker-compose version is required to parse v2 YAML documents.

Build process failed: Unknown instruction: ARG

I'm trying my first Docker Hub automated build using a Dockerfile I have successfully built locally. On Docker Hub, it fails with this output
Cloning into 'brx9syjpjlk9bnmymmynwpl'...
Warning: Permanently added the RSA host key for IP address '104.192.143.2' to the list of known hosts.
KernelVersion: 3.13.0-40-generic
Os: linux
BuildTime: Mon Oct 12 05:37:18 UTC 2015
ApiVersion: 1.20
Version: 1.8.3
GitCommit: f4bf5c7
Arch: amd64
GoVersion: go1.4.2
Step 0 : FROM ubuntu:14.04
---> c4bea91afef3
Step 1 : ARG
Unknown instruction: ARG
I have found no way to pass a build-arg to the automated build, but my ARG's default value is sane, so that shouldn't matter.
Any ideas what the problem here is?
Docker Hub's automated build is still running Docker 1.8 and doesn't support ARG yet. There is a github issue tracking their upgrade to 1.9.
We encountered the same issue on Travis.ci. Upgrading to Docker Engine 1.9.0 worked for us.
We added this to our travis.yml
before_script:
- sudo apt-get update
- sudo apt-get install -y -q docker-engine=$DOCKER_ENGINE_VERSION

Docker Client server different. And there is no boot2docker

My machine debian VM. It is not having boot2docker.
Docker was installed in it. I somehow updated docker.It is now giving me error of client and server of not same version.
by running "docker version" gives me this
Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.3.3
Git commit (client): 5bc2ff8
OS/Arch (client): linux/amd64
FATA[0000] Error response from daemon: client and server don't have same version (client : 1.16, server: 1.15)
Thanks in advance.
If you do not have images or containers you wish to keep, remove and install again the latest docker version, with sudo apt-get remove lxc-docker && sudo apt-get purge lxc-docker && sudo apt-get install lxc-docker
One way to deal with this is dvm, the Docker Version Manager.
Clone it to, e.g. ~/.dvm:
git clone https://github.com/rgbkrk/dvm.git ~/.dvm
Then you need to source it directly or place it in your bash profile:
. ~/.dvm/dvm.sh
After this, install the version of docker you need:
$ dvm install 1.6.1
######################################################################## 100.0%
Now using Docker 1.6.1
You can swap between versions through dvm use VERSION:
$ dvm use 1.8.2
Now using Docker 1.8.2

Resources