skip to Main Content

I am trying to run CI/CD in Azure pipeline .Because my app need some dependencies that only work ubuntu 18.04 however that VmImage version deprecated in Azure hosted agent. That is why I run it on ubuntu 18.04 docker container. It seem the docker container does not have sudo installed so I try to install it. Here is my pipeline code

  pool: 
    vmImage: ubuntu-latest
  container: ubuntu:18.04
  dependsOn: ImpactedProjects
  condition: eq(dependencies.ImpactedProjects.outputs['ImpactAnalysis.Project.Loyalty.QueryCachePopulator.AzureFunction.BddTests'], 'True')
  steps:
  - script: apt-get install sudo
    displayName: 'Install sudo'

However then I got this error

E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
##[error]Bash exited with code '100'.
Finishing: Install sudo

Is there anyone know how to fix this please. Thanks

2

Answers


  1. You will need to be the root user within the Docker container so you can install packages. If you’re running this with a docker run command, try setting the following environment variables as part of your docker run command:

    -e USERID=0 -e GROUPID=0
    
    Login or Signup to reply.
  2. I can reproduce the same issue when using the ubuntu 18.04 in Container job.

    enter image description here

    The cause of this issue is that this image runs as non-root, so for root-access things you have to switch into root.

    In a Dockerfile, you can simply switch user identities with a USER directive; this generally defaults to running as root:

    USER root
    

    To resolve this issue, you need to custom your docker image based on the image: ubuntu18.04.

    For example:

    FROM ubuntu:18.04
    USER root
    RUN apt-get update && apt-get install -y 
    RUN apt-get install sudo
    USER 1001
    

    Then you can use the custom image in container job.

    For example:

    pool: 
      vmImage: ubuntu-latest
    container: 
     image: xxx/ubuntu18.04:23787
     endpoint: dockerserviceconnection
     options: --user root --privileged
    
    steps:
    - script: sudo apt-get install sudo
    

    For more detailed info, you can refer to this ticket and doc: Container Job Option

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search