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
You will need to be the
root
user within the Docker container so you can install packages. If you’re running this with adocker run
command, try setting the following environment variables as part of yourdocker run
command:I can reproduce the same issue when using the ubuntu 18.04 in Container job.
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:
To resolve this issue, you need to custom your docker image based on the image:
ubuntu18.04
.For example:
Then you can use the custom image in container job.
For example:
For more detailed info, you can refer to this ticket and doc: Container Job Option