Search code examples
gitdockerubuntusudoapt

Docker not able to install git on Ubuntu container


I have a Docker image that uses ubuntu:21.04. When I SSH onto it I try to install git using the official Git Ubuntu installation instructions but I get an error:

root@c812b171354a:/home/ubuntu# sudo apt install git-all
bash: sudo: command not found

I'm surprised to see sudo doesn't exist! So I try it without sudo:

root@c812b171354a:/home/ubuntu# apt install git-all
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package git-all

So I ask: what command(s) can I run to install git on a Dockerized Ubuntu 21.04 container?

Update

Here is my full Dockerfile:

FROM ubuntu:21.04

COPY keep-alive.sh /home/ubuntu/keep-alive.sh

# give keep-alive script permission to run
RUN ["chmod", "+x", "/home/ubuntu/keep-alive.sh"]

# install git
RUN apt update -y
RUN apt install -y gpgv2 git-all

CMD ["/bin/bash", "-c", "/home/ubuntu/keep-alive.sh"]

When I build the image:

docker build -t myorg/linux-worker .

I get:

Sending build context to Docker daemon   7.68kB
Step 1/6 : FROM ubuntu:21.04
 ---> 478aa0080b60
Step 2/6 : COPY keep-alive.sh /home/ubuntu/keep-alive.sh
 ---> Using cache
 ---> e1bcc0d7dd20
Step 3/6 : RUN ["chmod", "+x", "/home/ubuntu/keep-alive.sh"]
 ---> Using cache
 ---> ef46c36ec41b
Step 4/6 : RUN apt update -y
 ---> Running in fee517c02852

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Get:1 http://security.ubuntu.com/ubuntu hirsute-security InRelease [101 kB]
Err:1 http://security.ubuntu.com/ubuntu hirsute-security InRelease
  gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Get:2 http://archive.ubuntu.com/ubuntu hirsute InRelease [269 kB]
Err:2 http://archive.ubuntu.com/ubuntu hirsute InRelease
  gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Get:3 http://archive.ubuntu.com/ubuntu hirsute-updates InRelease [109 kB]
Err:3 http://archive.ubuntu.com/ubuntu hirsute-updates InRelease
  gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Get:4 http://archive.ubuntu.com/ubuntu hirsute-backports InRelease [90.7 kB]
Err:4 http://archive.ubuntu.com/ubuntu hirsute-backports InRelease
  gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Reading package lists...
W: GPG error: http://security.ubuntu.com/ubuntu hirsute-security InRelease: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
E: The repository 'http://security.ubuntu.com/ubuntu hirsute-security InRelease' is not signed.
W: GPG error: http://archive.ubuntu.com/ubuntu hirsute InRelease: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
E: The repository 'http://archive.ubuntu.com/ubuntu hirsute InRelease' is not signed.
W: GPG error: http://archive.ubuntu.com/ubuntu hirsute-updates InRelease: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
E: The repository 'http://archive.ubuntu.com/ubuntu hirsute-updates InRelease' is not signed.
W: GPG error: http://archive.ubuntu.com/ubuntu hirsute-backports InRelease: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
E: The repository 'http://archive.ubuntu.com/ubuntu hirsute-backports InRelease' is not signed.
The command '/bin/sh -c apt update -y' returned a non-zero code: 100

Are there any other dependencies I need?


Solution

  • The Ubuntu image comes with nothing in the package listings, so you need to apt update then apt install git-all.

    Add the -y options to those if you put them in RUN commands in the Dockerfile.