Configure git in Dockerfile with base of Ubuntu

I understand that the official image for Ubuntu does not have git built-in. So I am creating a Dockerfile using Ubuntu as the base, and then build a new image, like this:

# Base image is Ubuntu 18.04
FROM ubuntu:18.04

# Update software repository
RUN apt-get update

# Install git, then remove cache
RUN apt-get install -y git

But I don’t think this is the best way, since it is not only slow, but very manual. I wonder if there are official images, or better ways to install git, as well as necessary packages in a bare bone Ubuntu Docker image. Thanks!

Source: StackOverflow