Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Docker push failing - tag does not exist

Nisanth Reddy March 11, 2024

My bitbucket pipelines are failing with tag does not exist referring to  dockerhub image push

 

 

this is the bitbucket-pipelines.yaml config

 

image: node:8

pipelines:
default:
- step:
name: Build Docker Image
caches:
- docker
script:
- echo 'Building Docker image but skipping Deploy for feature branch'
- sh ./build-docker.sh
branches:
development:
- step:
name: Deploy to Development
caches:
- docker
deployment: test
script:
- export DOCKER_BUILDKIT=0
- export LABEL=$(TZ=':America/Phoenix' date +%Y%m%d%H%M)
- sh ./deploy.sh development ${LABEL}
staging:
- step:
name: Deploy to Staging
caches:
- docker
deployment: staging
script:
- export DOCKER_BUILDKIT=0
- export LABEL=$(TZ=':America/Phoenix' date +%Y%m%d%H%M)
- sh ./deploy.sh staging ${LABEL}
qa:
- step:
name: Deploy to QA
caches:
- docker
deployment: production
script:
- export DOCKER_BUILDKIT=0
- export LABEL=$(TZ=':America/Phoenix' date +%Y%m%d%H%M)
- sh ./deploy.sh qa ${LABEL}
demo:
- step:
name: Deploy to Demo
caches:
- docker
deployment: test
script:
- export DOCKER_BUILDKIT=0
- export LABEL=$(TZ=':America/Phoenix' date +%Y%m%d%H%M)
- sh ./deploy.sh demo ${LABEL}

master:
- step:
name: Deploy to Production
caches:
- docker
deployment: production
script:
- export DOCKER_BUILDKIT=0
- export LABEL=$(TZ=':America/Phoenix' date +%Y%m%d%H%M)
- sh ./deploy.sh master ${LABEL}
options:
docker: true

 

 

build-docker.sh 

 

#!/usr/bin/env bash
ENVIRONMENT=${1}
BITBUCKET_COMMIT=${BITBUCKET_COMMIT}
BITBUCKET_BRANCH="${BITBUCKET_BRANCH:-${ENVIRONMENT}}"
# Build Docker image
docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}
docker build -t intraedge/truyo-php:${ENVIRONMENT}-${BITBUCKET_COMMIT} -t intraedge/truyo-php:${ENVIRONMENT} --build-arg env=${ENVIRONMENT} .

if [[ $BITBUCKET_BRANCH == 'oci-poc' ]] || [[ $BITBUCKET_BRANCH == 'development' ]] || [[ $BITBUCKET_BRANCH == 'staging' ]] || [[ $BITBUCKET_BRANCH == 'qa' ]] || [[ $BITBUCKET_BRANCH == 'master' ]]; then
# and push to repository
docker push intraedge/truyo-php:${ENVIRONMENT}
docker push intraedge/truyo-php:${ENVIRONMENT}-${BITBUCKET_COMMIT}

fi;

 

and deploy.sh

#!/usr/bin/env bash

ENV=${1}
COMMIT=${BITBUCKET_COMMIT}-${2}

# Build Docker image and push to repository
docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}
docker build -t intraedge/truyo-php:${ENV}-${COMMIT} -t intraedge/truyo-php:${ENV} --build-arg env=${ENV} .
docker push intraedge/truyo-php:${ENV}
docker push intraedge/truyo-php:${ENV}-${COMMIT}

 

the docker version being used is

 

+ docker version
2
Client:
3
Version: 20.10.24
4
API version: 1.39
5
Go version: go1.19.7
6
Git commit: 297e128
7
Built: Tue Apr 4 18:17:06 2023
8
OS/Arch: linux/amd64
9
Context: default
10
Experimental: true
11

 

check the below article which mentions same issue as mine

https://confluence.atlassian.com/bbkb/docker-push-failing-tag-does-not-exist-1142430671.html

 

In June 2022, Bitbucket Pipelines upgraded to Docker CLI version v20.10.15. Prior to Docker CLI version 20, the docker push command would push all available image tags if no tag was specified. For version 20, the Docker CLI updated the docker push command to try to push the latest tag, if a tag is not specified. If the latest tag does not exist, the command will fail.

 

It mentions 

Downgrading or using an alternative client might help.

 

But this did not help us

pipelines:
default:
- step:
services:
- docker
script:
- curl -s -O https://download.docker.com/linux/static/stable/x86_64/docker-19.03.15.tgz
- tar --extract --file=docker-19.03.15.tgz
- ls -al ./docker
- export PATH=./docker:$PATH
- which docker
- docker version

 any other solution would be appreciated

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 12, 2024

Hi @Nisanth Reddy,

The first line of the build-docker.sh is

ENVIRONMENT=${1}

${1} refers to the first command-line argument passed to the shell script, but in your yml file you are not passing any arguments to the script:

- sh ./build-docker.sh

So, the ENVIRONMENT variable (which is used for the tags of the Docker image you build) is empty.

Can you try adjusting the command and passing an argument to the script?

The knowledge base article you posted is not relevant because it concerns cases where no tag is specified in the docker push command. Your docker push commands include tags with the image.

Can you also please confirm if you have in your yml file

services:
- docker

for the step

or

options:
docker: true

at the top level. You would see a different error without one of these options, but I just wanted to bring it up because you are running docker commands and the yml you posted here doesn't include an option for the docker service.

Kind regards,
Theodora

Nisanth Reddy March 12, 2024

Hi @Theodora Boudale  thanks for responding, I can confirm that 

options:
docker: true is enabled in the bitbucket-pipelines.yaml file
Nisanth Reddy March 12, 2024

@Theodora Boudale I added the entire code of pipeline.yaml and the docker version.

 

Thanks & Regards,

Nisanth Reddy

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 12, 2024

Hi @Nisanth Reddy,

Thank you for sharing additional info.

Your yml file has several pipelines. There is the default pipeline, and the branches pipelines development, staging, qa, demo, master.

When you run the sh ./deploy.sh command in the branches pipelines, you specify arguments. For example, the command in the development pipeline is

- sh ./deploy.sh development ${LABEL}

In this case, ${1} refers to development and the variable ENVIRONMENT has the value development.

However, the default pipeline has the command

- sh ./build-docker.sh

so there are no arguments to the script and ${1} is empty (and ENVIRONMENT is also empty).

Is it the default pipeline that shows this error or one of the branches pipeline?

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events