Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to build Docker Image with packer via Bitbucket pipelines

David Foley
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 17, 2025

Hi All,

Trying to Build a Docker Image using Bitbucket pipelines, with a custom bitbucket pipe
I'm using the Same Custom pipe for building ECR Images which is working have customize it to only take in less parameters for the Docker build. 

ERROR I'm Getting 

INFO: Running packer init command

INFO: ==> tomcat9.docker.tomcat: 6edc54ec3599: Pulling fs layer

INFO: ==> tomcat9.docker.tomcat: e153ad7211e4: Pull complete

INFO: ==> tomcat9.docker.tomcat

INFO: Build 'tomcat9.docker.tomcat' errored after 7 seconds 451 milliseconds: Error running container: Docker exited with a non-zero exit status




INFO: Stderr: docker: Error response from daemon: authorization denied by plugin pipelines: -v only supports $BITBUCKET_CLONE_DIR and its subdirectories

INFO: See 'docker run --help'.


I've tried different things within the Packer file, but keep getting the Same Error  BITBUCKET_CLONE_DIR


Packer.HCL 

variable "apm_version" {

  type    = string

}

variable "source_name" {

  type = string

}

variable "tomcat_images" {

  type = map(string)

  default = {

    tomcat9    = "public.ecr.aws/docker/library/tomcat:9-jdk8-corretto"

    corretto11 = "public.ecr.aws/amazoncorretto/amazoncorretto:11"

  }

}

variable "ecr_repo_url" {

  type = map(string)

  default = {

    tomcat9    = ""

    corretto11 = "

  }

}

packer {

  required_plugins {

    docker = {

      version = ">=1.1.0"

      source  = "github.com/hashicorp/docker"

    }

  }

}

source "docker" "tomcat" {

  image  = var.tomcat_images[var.source_name]

  commit = true

}

build {

  name    = var.source_name

  sources = ["source.docker.tomcat"]

  provisioner "shell" {

    inline = [

      "yum update && yum install -y wget",

      "mkdir -p /app",

      var.source_name == "corretto11" ?

        "wget -O /app/agent.jar https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/${var.apm_version}/elastic-apm-agent-${var.apm_version}.jar" :

        "wget -O /app/agent.jar https://search.maven.org/remotecontent?filepath=co/elastic/apm/elastic-apm-agent/${var.apm_version}/elastic-apm-agent-${var.apm_version}.jar"

    ]

  }

  post-processors {

    post-processor "docker-tag" {

      repository = var.ecr_repo_url[var.source_name]

      tags       = [var.apm_version]

    }

    post-processor "docker-push" {

      ecr_login           = true

      login_server        = var.ecr_repo_url[var.source_name]

      keep_input_artifact = false

    }

  }

}

Pipeline

image: atlassian/default-image:4

definitions:

  steps:

    - step: &PackerBuild

        name: 'Build Packer Image'

        oidc: true

        script:

          - cat deploy_vars.txt

          - source deploy_vars.txt

          - pipe: docker://davefoley/bitbucket-docker:v2

            variables:

              AWS_DEFAULT_REGION: 'eu-west-1'

              AWS_ROLE_ARN: $ARN

              AWS_ROLE_SESSION_NAME: $SESSIONROLENAME

              PACKER_SOURCE_NAME: $SOURCE

              APMVersion: $APMAgentVersion

        artifacts:

          - manifest.json

pipelines:

  branches:

    main:

      - stage:

          name: 'Build Tomcat Image'

          steps:

            - step:

                name: 'Parameters'

                script:

                  - export APMAgentVersion=1.52.0

                  - export SOURCE=tomcat9

                  - export ARN=arn:aws:iam:::role/ssm--

                  - export SESSIONROLENAME=--

                  - echo "APMAgentVersion=$APMAgentVersion" >> deploy_vars.txt

                  - echo "SOURCE=$SOURCE" >> deploy_vars.txt

                  - echo "ARN=$ARN" >> deploy_vars.txt

                  - echo "SESSIONROLENAME=$SESSIONROLENAME" >> deploy_vars.txt

                artifacts:

                  - deploy_vars.txt

            - step: *PackerBuild

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events