Run docker compose inside a bitbucket pipeline - docker

I need to run docker-compose with --exit-code-from . My local docker-compose binary accepts this command line and works just fine.
+ docker-compose -f file1.yml -f file2.yml up zookeeper-secure kafka-secure schema-registry-secure app integration-tests --exit-code-from integration-tests
However, I need to run this in a bitbucket pipeline. To achieve that I installed docker-compose using pip installer
pip install docker-compose
Which gives me version 1.29.2
+ docker-compose version
docker-compose version 1.29.2, build unknown
docker-py version: 5.0.3
CPython version: 3.7.12
OpenSSL version: OpenSSL 1.1.1d 10 Sep 2019
And this version probably does not honour --exit-code-from and hence errors out
No such service: --exit-code-from
While looking into docker docs, i found compose is now available in docker cli itself (though not very clear from which version onwards), but my bitbucket pipeline does not recognise that too.
+ docker compose help
docker: 'compose' is not a docker command.
See 'docker --help'
Here is the docker version output inside my bitbucket pipeline
+ docker version
Client:
Version: 20.10.15
API version: 1.41
Go version: go1.17.9
Git commit: fd82621
Built: Thu May 5 13:10:20 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.15
API version: 1.41 (minimum version 1.12)
Go version: go1.17.9
Git commit: 4433bf6
Built: Thu May 5 13:10:29 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.6.4
GitCommit: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
runc:
Version: 1.1.1
GitCommit: v1.1.1-0-g52de29d7
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Any help will be much appreciated !

Since the --exit-code-from option was introduced in April 2017, v1.12.0, I think the docker-compose v1 CLI parser is being much more picky than the docker-compose v2 you probably have in your workstation.
Telling by the No such service: --exit-code-from error message, simply move the option after the up subcommand but before the service list begins:
docker-compose \
-f file1.yml \
-f file2.yml \
up \
--exit-code-from integration-tests \
zookeeper-secure kafka-secure schema-registry-secure app integration-tests
Very much related: https://stackoverflow.com/a/59840305/11715259
Otherwise, this question is about "how to use docker-compose v2 in Bitbucket Pipelines", which is a totally different topic: https://stackoverflow.com/a/73069569/11715259

Related

Create ECS Context with Docker without Docker Desktop

I'm trying to create an ECS context using Docker so that I can deploy to AWS using the Docker Compose CLI
docker context create ecs <my context name>
But am receiving the following error:
"docker context create" requires exactly 1 argument.
See 'docker context create --help'.
Usage: docker context create [OPTIONS] CONTEXT
Create a context
I've edited my /etc/docker/daemon.json to include
{
"experimental": true
}
My Docker Compose CLI is version 2.14.2 and both the Client and Server show experimental as true
Client:
Version: 20.10.22
API version: 1.41
Go version: go1.19.4
Git commit: 3a2c30b63a
Built: Tue Dec 20 20:43:40 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.22
API version: 1.41 (minimum version 1.12)
Go version: go1.19.4
Git commit: 42c8b31499
Built: Tue Dec 20 20:42:46 2022
OS/Arch: linux/amd64
Experimental: true
containerd:
Version: v1.6.14
GitCommit: 9ba4b250366a5ddde94bb7c9d1def331423aa323.m
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d1
docker-init:
Version: 0.19.0
GitCommit: de40ad0
This should be available in Docker since 19.03
https://docs.docker.com/cloud/ecs-integration/#install-the-docker-compose-cli-on-linux
So far I've only been able to create an ECS context by installing Docker with the experimental Arch package for Docker Desktop instead of Docker Compose Standalone. The weird thing is, Docker Desktop's Docker Compose version is only 2.13.
This also might be related to this question:
docker context create ecs myecs - requires exactly one argument

When I execute the compose.yml file, I get ERROR: Client version 3.8 is too new. The maximum supported API version is 1.41

The problem I'm having executing the compose command reports an error.
ERROR: client version 3.8 is too new. maximum supported API version is 1.41
I am now confused about the version directive under the compose.yml file. What exactly does the version of this directive mean and what is the relationship between it and docker version
Does anyone know how to solve this problem, thanks a lot!
Info 1:
Here's my docker version info
D:\Docker\www\laravel-madmin\localHost\docker>docker-compose up --build -d
ERROR: client version 3.8 is too new. Maximum supported API version is 1.41
D:\Docker\www\laravel-madmin\localHost\docker>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
D:\Docker\www\laravel-madmin\localHost\docker>docker version
Client:
Cloud integration: v1.0.24
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:53:11 2022
OS/Arch: windows/amd64
Context: default
Experimental: true
Server: Docker Desktop 4.8.2 (79419)
Engine:
Version: 20.10.14
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 87a90dc
Built: Thu Mar 24 01:46:14 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.11
GitCommit: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Info 2:
Here's my docker-compose.yml info
version: "3.8"
services:
php-fpm-8.1.6:
build:
context: ../../
dockerfile: /localHost/docker/php8.1.6/Dockerfile
hostname: ${COMPOSE_PROJECT_NAME}-${HOST_NAME}-php-fpm-8.1.6
container_name: ${COMPOSE_PROJECT_NAME}-${CONTAINER_NAME}-php-fpm-8.1.6
networks:
- backend
environment:
- TZ=${TIME_ZONE}
Info 3:
Here's my dockerfile.yml info
FROM php:8.1.6-fpm
WORKDIR /www
COPY . /www
RUN docker-php-source extract \
&& pecl install xdebug-3.1.4 \
&& docker-php-ext-enable xdebug \
&& docker-php-source delete \
Info 4:compose version
docker compose version
Docker Compose version v2.5.1
Here are the compose versions supported by the docker engine that I copied from the official docker website
Compatibility matrix
There are several versions of the Compose file format – 1, 2, 2.x, and 3.x
This table shows which Compose file versions support specific Docker releases.
Compose file format Docker Engine release
Compose specification 19.03.0+
3.8 19.03.0+
3.7 18.06.0+
3.6 18.02.0+
question 1:
Some say the problem is caused by a mismatch in the interface。
But as you can see from the picture above, my docker version is 20.10.14 and the supported compose version is greater than 3.8, so why does setting version=3.8 in the composeoe.yml file prompt an error?
question 2:
In Info 1, you can see a version information: API version: 1.41, this version is exactly the maximum version number in the error message。
ERROR: client version 3.8 is too new. Maximum supported API version is 1.41
My confusion is what is the relationship between the version number 1.41 here and the version number in compse.yml, should I set version=1.41 or version=3.8 it, even if I set version=1.41, it will also prompt the following error
ERROR: Version in ".\docker-compose.yml" is invalid. 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/
Can anyone help me, thanks in advance
I have found the cause of this problem,It's my own cause。
because I have another .env file, I thought the version parameter of compose.yml and COMPOSE_API_VERSION are the same. So I defined COMPOSE_API_VERSION=3.8 in the .env file, but the actual COMPOSE_API_VERSION max version number is 1.41. So the versions parameter of compose.yml should not be the same thing with COMPOSE_API_VERSION. After canceling COMPOSE_API_VERSION=3.8, the command can be executed normally
#<------docker-compose.yml配置文件---------->#
####################docker系统变量 #####################
#项目名称
COMPOSE_PROJECT_NAME=my-project
COMPOSE_API_VERSION=3.8
#compose版本
#时区
TIME_ZONE=Asia/Shanghai
####################用户自定义变量 #####################
#容器名称
CONTAINER_NAME=container
HOST_NAME=host
NETWORKS_NAME=networks
VOLUME=volume
Thank you for your answers

gcr.io registry, docker buildx multi-plaftorm --push 401: authorization failed

I'm facing an unauthorized issue when using docker buildx build --platform linux/amd64 -f Dockerfile -t gcr.io/<bucket>/<image>:1.0.0 --push . when pushing to gcr.io/<bucket>. I listed one platform here, but the problem is the same with multiple platforms.
However, it works when doing a --load action followed by a manual docker push:
docker buildx build --platform linux/amd64 -f Dockerfile -t gcr.io/<bucket>/<image>:1.0.0 --load .
docker push gcr.io/<bucket>/<image>:1.0.0
What is the proper configuration I need to be able to use docker buildx build with --push directly to push to a GCR registry? I'm authenticated to GCP with gcloud auth login and did gcloud auth configure-docker. The standard docker push works so I assume the configuration is good for this use case.
If you don't know the answer but know how where I could get support from GCR team about this, please post the link in a comment and I'll follow up there to see what's wrong.
Some information about my setup:
$ gcloud --version
Google Cloud SDK 377.0.0
alpha 2022.03.10
bigtable
bq 2.0.74
cbt 0.11.0
core 2022.03.10
gsutil 5.8
kubectl 1.21.9
minikube 1.25.2
$ docker version
Client:
Cloud integration: v1.0.22
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:46:56 2021
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:43:07 2021
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0

Docker Hello-world fails with "no such file or directory"

OS: Ubuntu cinammon 20.04
I followed the directions from here: docker documentation
When I get to the step to run the Hello-world image.
$ sudo docker run hello-world docker: Error response from daemon: open /var/lib/docker/aufs/layers/9cd449051217b6dc5c24c81e1a02ef897eeb90ee62421d6a227ddfbeddc2b70c-init: no such file or directory. See 'docker run --help'.
`
I've stopped and started the daemon.
sudo service docker stop sudo service docker start
and
systemctl restart docker
The image exists locally per:
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 6 months ago 13.3kB
I've been Googling this and getting nowhere. I've seen other places where restarting the daemon fixes it, but I'm just not that lucky.
Any ideas??
More info:
$ sudo docker version
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:45:44 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.12
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:44:15 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683

Docker Run commands

When I am trying to run the below docker run command on our linux servers
docker run --name test-image -d -p 9081:8080 -v /usr/Jenkins2/container:/var/jenkins_home docker.io/jenkins
It shows flag needs an argument: 'p' in -p
See 'docker run --help'.
Error image
If I use the below command it works fine
docker run --name test-image -d docker.io/jenkins
What I observed was if I issue the docker run command with two flags it works fine, but if I use more than two it says flag needs an argument.
**Docker version Output:**
Client:
Version: 1.13.1
API version: 1.26
Package version: <unknown>
Go version: go1.8.3
Git commit: 774336d/1.13.1
Built: Tue Feb 20 13:46:34 2018
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: <unknown>
Go version: go1.8.3
Git commit: 774336d/1.13.1
Built: Tue Feb 20 13:46:34 2018
OS/Arch: linux/amd64
Experimental: false
****os-release output:****
NAME="Red Hat Enterprise Linux Server"
VERSION="7.4 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="7.4"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.4 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.4:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.4
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.4"
I tried the same command on my personal laptop which is using docker-ce version it works fine. Can someone help me if I am missing anything here.

Resources