See in depth tutorial here.
Run following:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
If you want to use docker without invoking sudo
check this.
In order to use Docker with GPU check official NVIDIA container toolkit instructions here.
Nice explanation about hardware acceleration in ROS can be seen here.
ROS 2 Hardware acceleration check here.