question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running in Docker

See original GitHub issue

Hi @lucacasonato !

I am trying to create a docker image where I use Deno with Oak and Puppeteer, but I am having some issues with Puppeteer. So far, this is my docker image, but I cannot seem to make it work. I have two main issues at the moment:

1: The install script does not seem to recognize that an existing installation exists 2: Puppeteer is not able to run the downloaded chromium

Here is my Dockerfile (assume that all the variables are set). Let me know if I can provide you with any other information!

FROM hayd/alpine-deno:1.7.2

EXPOSE ${MICROSERVICE_PORT}

WORKDIR /app

# As provided by https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-on-alpine
RUN apk add --no-cache \
      nss \
      freetype \
      freetype-dev \
      harfbuzz \
      ca-certificates \
      ttf-freefont 


ENV PUPPETEER_EXECUTABLE_PATH=/deno-dir/deno_puppeteer/chromium/linux-818858/chrome-linux/chrome

ADD . .

RUN PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@${PUPPETEER_VERSION}/install.ts

RUN deno install -qAf --unstable https://deno.land/x/denon/denon.ts

RUN deno cache --unstable src/deps.ts

RUN deno cache --unstable src/mod.ts

USER deno

ENTRYPOINT [ "denon"]

CMD ["run","--unstable","-A","src/mod.ts" ]

This is the error that I am receiving when I try to use Puppeteer:

Error: Failed to launch the browser process!
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at waitForWSEndpoint (BrowserRunner.ts:174:9)
    at async BrowserRunner.setupConnection (BrowserRunner.ts:143:31)
    at async ChromeLauncher.launch (Launcher.ts:108:26)
    at async createPDF (pdf-handler.ts:4:19)
    at async routes.ts:14:19
    at async dispatch (middleware.ts:41:7)
    at async dispatch (middleware.ts:41:7)
    at async dispatch (middleware.ts:41:7)
    at async Application.#handleRequest (application.ts:252:9)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
mt-ucommented, May 18, 2021

Hi @lucacasonato, @halvardssm.

I solved this. I checked the error message by adding console.log (line); between lines 167 and 168 of BrowserRunner.ts in deno-puppeteer. I found that the cause of the error was that some required packages were not installed. The packages listed in troubleshooting of puppeteer are not enough for Docker containers, need the following:

libdrm2
libxkbcommon0
libxshmfence1

And one more important thing is written here. If we run as root user inside a Docker container, we need to use --no-sandbox mode when launching Puppeteer. Otherwise error will occur. Yet one more thing, Troubleshooting has tips on shared memory issues in Docker containers. Based on these, the parameters of the launch method should be as follows:

const browser = await puppeteer.launch({
  args: [
    '--no-sandbox',
    '--disable-dev-shm-usage'
  ],
});

This is my Dockerfile:

FROM debian:buster-slim

ENV DENO_VERSION=1.10.1
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get -qq update \
    && apt-get -qq install -y --no-install-recommends \
    curl \
    ca-certificates \
    unzip \
# ↓ https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix
# Since I want to leave the contents of troubleshooting.md as it is, ca-certificates is intentionally duplicated here.
    ca-certificates \
    fonts-liberation \
    libappindicator3-1 \
    libasound2 \
    libatk-bridge2.0-0 \
    libatk1.0-0 \
    libc6 \
    libcairo2 \
    libcups2 \
    libdbus-1-3 \
    libexpat1 \
    libfontconfig1 \
    libgbm1 \
    libgcc1 \
    libglib2.0-0 \
    libgtk-3-0 \
    libnspr4 \
    libnss3 \
    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 \
    lsb-release \
    wget \
    xdg-utils \
# ↑ https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix
# ↓ Added based on the information obtained from by console.log(line) at https://deno.land/x/puppeteer@9.0.0/src/deno/BrowserRunner.ts#L168.
    libdrm2 \
    libxkbcommon0 \
    libxshmfence1 \
# ↑ Added based on the information obtained from by console.log(line) at https://deno.land/x/puppeteer@9.0.0/src/deno/BrowserRunner.ts#L168.
    && curl -fsSL https://github.com/denoland/deno/releases/download/v${DENO_VERSION}/deno-x86_64-unknown-linux-gnu.zip \
    --output deno.zip \
    && unzip deno.zip \
    && rm deno.zip \
    && chmod 755 deno \
    && mv deno /usr/bin/deno \
    && apt-get -qq remove --purge -y \
    curl \
# Do not remove ca-certificates as it is required by puppeteer.
#    ca-certificates \
    unzip \
    && apt-get -y -qq autoremove \
    && apt-get -qq clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN useradd --uid 1993 --user-group deno \
 && mkdir /deno-dir/ \
 && chown deno:deno /deno-dir/

ENV DENO_DIR /deno-dir/

# https://deno.land/x/puppeteer@9.0.0#installation
RUN PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@9.0.0/install.ts

WORKDIR /root
ENTRYPOINT ["deno"]
CMD ["run", "https://deno.land/std/examples/welcome.ts"]

Thank you.

3reactions
lucacasonatocommented, May 20, 2021

Added an example Dockerfile and info to the README. Thanks everyone for figuring this out. Especially @mt-u who got it working in the end 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

docker run - Docker Documentation
The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command.
Read more >
How To Use docker exec to Run Commands in ... - DigitalOcean
Running Commands in an Alternate Directory in a Docker Container. To run a command in a certain directory of your container, use the...
Read more >
A Docker Tutorial for Beginners
We can download and run the image directly in one go using docker run . As noted above, the --rm flag automatically removes...
Read more >
Running Containers – Introduction to Docker - GitHub Pages
To use a Docker image as a particular instance on a host machine you run it as a container. You can run in...
Read more >
Docker basics: how to start and stop containers - Elder Moraes
If you skip the TAG and DIGEST command parameters, Docker will run the container based on the image tagged latest. The docker run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found