I'm trying to build Docker image with Tor Browser and my simple Kotlin application inside. My application is functioning well locally on MacOS, but when I try to run it inside Docker container, it fails with the following error:
1607374979695 mozrunner::runner INFO Running command: "/app/Browser/firefox" "--marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileqZSjZi"
*** You are running in headless mode.
JavaScript warning: moz-extension://af4f80b4-d782-4331-853f-f8896990a27a/js/background.js, line 1: unreachable code after return statement
JavaScript warning: moz-extension://af4f80b4-d782-4331-853f-f8896990a27a/js/background.js, line 1: unreachable code after return statement
JavaScript warning: moz-extension://af4f80b4-d782-4331-853f-f8896990a27a/js/background.js, line 1: unreachable code after return statement
JavaScript warning: moz-extension://af4f80b4-d782-4331-853f-f8896990a27a/js/background.js, line 1: unreachable code after return statement
JavaScript warning: moz-extension://af4f80b4-d782-4331-853f-f8896990a27a/js/background.js, line 1: unreachable code after return statement
Exiting due to channel error.
org.openqa.selenium.TimeoutException: Connection refused (os error 111)
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: '29cd09cc70bb', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.39-linuxkit', java.version: '1.8.0_275'
Driver info: driver.version: FirefoxDriver
Dockerfile that I built:
FROM adoptopenjdk/openjdk8:slim
# Set environment variables
ENV APP_NAME="Tor Browser" \
TOR_VERSION=10.0.5 \
TOR_BINARY=https://www.torproject.org/dist/torbrowser/10.0.5/tor-browser-linux64-10.0.5_en-US.tar.xz \
TOR_SIGNATURE=https://www.torproject.org/dist/torbrowser/10.0.5/tor-browser-linux64-10.0.5_en-US.tar.xz.asc \
TOR_FINGERPRINT=0xEF6E286DDA85EA2A4BA7DE684E2C6E8793298290 \
DEBIAN_FRONTEND=noninteractive
# Add wget and Tor browser dependencies
RUN apt-get update && \
apt-get install -y gpg gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libdbus-glib-1-2 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget software-properties-common && \
rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Download binary and signature
RUN wget $TOR_BINARY && \
wget $TOR_SIGNATURE
# Verify GPG signature
RUN gpg --auto-key-locate nodefault,wkd --locate-keys torbrowser@torproject.org && \
gpg --output ./tor.keyring --export $TOR_FINGERPRINT && \
gpgv --keyring ./tor.keyring "${TOR_SIGNATURE##*/}" "${TOR_BINARY##*/}"
# Extract browser & cleanup
RUN tar --strip 1 -xvJf "${TOR_BINARY##*/}" && \
chown -R ${USER_ID}:${GROUP_ID} /app && \
rm "${TOR_BINARY##*/}" "${TOR_SIGNATURE##*/}"
RUN wget https://dist.torproject.org/torbrowser/10.0.5/geckodriver-linux64.tar.xz
RUN tar xf geckodriver-linux64.tar.xz && rm geckodriver-linux64.tar.xz
COPY build/libs libs/
COPY build/resources resources/
COPY build/classes/kotlin/main classes/
ENV FIREFOX_BINARY_PATH=/app/Browser/firefox
ENV TOR_GECKO_DRIVER_BINARY_PATH=/app/geckodriver
ENTRYPOINT ["sleep", "5000"]
Kotlin application:
fun main() {
System.setProperty("webdriver.gecko.driver", System.getenv("TOR_GECKO_DRIVER_BINARY_PATH"))
val profile = TorProfile()
profile.setPreference("network.proxy.socks_port", 9150)
val firefoxOptions = FirefoxOptions()
firefoxOptions.setProfile(profile)
firefoxOptions.setBinary(System.getenv("TOR_FIREFOX_BINARY_PATH"))
firefoxOptions.setHeadless(true)
val driver = FirefoxDriver(firefoxOptions)
}
Please, advice if anyone had similar problem or at least point where should I look. According to the logs, it seems firefox does not even start. Also the following log looks strange:
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'