I got all this working in a Dockerfile; see https://github.com/gkhays/dockerfiles/tree/master/oraclejdk8.
jdk-8u161-linux-x64.tar.gz
wget --no-cookies --no-check-certificate \
&& --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \
&& "http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz"
https://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/#
FROM ubuntu:latest
RUN apt-get update \
&& apt-get install -y wget \
&& rm -rf /var/lib/apt/lists/*
RUN JAVA_TGZ_FILE=jdk-8u161-linux-x64.tar.gz \
&& cd $JAVA_HOME \
&& tar -xvf $JAVA_TGZ_FILE --strip-components=1 \
&& rm $JAVA_TGZ_FILE src.zip