Azure Devp[s Pipeline Golang container Error :standard_init_linux.go:228: exec user process caused: no such file or directory

  azure-devops, docker, go

I have created a Azure devops Pipeline to build and puch docker image for a Golang API. If I do the "go build" in dockerfile it works but I want to build go project in separate task and then create a docker container separately. The container is created but when I run the conatiner I am getting error "standard_init_linux.go:228: exec user process caused: no such file or directory". Below is the dockerfile I am using :

FROM golang:1.16-alpine
ENV GOOS=linux 
ENV GOARCH=amd64
RUN mkdir -p /app
ADD . /app
WORKDIR /app
RUN ls
RUN go mod download
#RUN go build -o main
EXPOSE <PortName>
ENTRYPOINT [ "/app/main"]

My pipeline looks like this :

trigger:
- main

resources:
- repo: self

variables:
  tag: '$(Build.BuildId)'

stages:
- stage: Build
  displayName: Build image
  jobs:
 - job: Build
  displayName: Build
pool:
  vmImage: ubuntu-latest
  steps:
 - task: [email protected]
  inputs:
    version: '1.17.2'
- task: [email protected]
  inputs:
    command: 'get'
    arguments: '-d'
    workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: [email protected]
  inputs:
    command: 'build'
    arguments: '-o main'
    workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: [email protected]
  inputs:
    TargetFolder: '$(Build.ArtifactStagingDirectory)'    
- task: [email protected]
  inputs:
    containerRegistry: 'ContainerRegistryConnection'
    repository: 'APISetup'
    command: 'buildAndPush'
    Dockerfile: '**/Dockerfile'
    buildContext: '$(Build.ArtifactStagingDirectory)'
    tags: |
      $(Build.BuildId)
      Latest

In above doe if I enable "#RUN go build -o main" in docker file and just do [email protected] task with build context as .. then the container works fine .Please suggest what i might be missing.

Source: Docker Questions

LEAVE A COMMENT