Dockerize in new container

I'm trying to Dockerize a Crawlee Puppeteer project, but I'm stuck with it not finding Chromium. This is the current Dockerfile that I'm using:
# Specify the base Docker image. You can read more about
# the available images at https://crawlee.dev/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM node:16

# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version

RUN apt-get update && apt-get install -y wget gnupg ca-certificates
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update && apt-get install -y google-chrome-stable

# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./


# Run the image. If you know you won't need headful browsers,
# you can remove the XVFB start script for a micro perf gain.
CMD npm start
# Specify the base Docker image. You can read more about
# the available images at https://crawlee.dev/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM node:16

# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version

RUN apt-get update && apt-get install -y wget gnupg ca-certificates
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update && apt-get install -y google-chrome-stable

# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./


# Run the image. If you know you won't need headful browsers,
# you can remove the XVFB start script for a micro perf gain.
CMD npm start
If somebody can help me a bit.
3 Replies
rare-sapphire
rare-sapphire•3y ago
Hi @NeoNomade , you should use the apify/actor-node-puppeteer-chrome image which comes with chromium.
MEE6
MEE6•3y ago
@vojtechmaslan just advanced to level 3! Thanks for your contributions! 🎉
NeoNomade
NeoNomadeOP•3y ago
I'm deploying in a separate infrastructure, with different needs. This is why I'm building a new dockerfile @vojtechmaslan New docker file :
FROM node:current-alpine
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
USER root
WORKDIR /usr/src/app
COPY package*.json ./
RUN chmod 744 package-lock.json
RUN apk add chromium

# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install \
&& echo "Installed NPM packages:" \
&& (npm list --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version

# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./
ENV CRAWLEE_CHROME_EXECUTABLE_PATH=/usr/bin/chromium-browser
RUN chmod 744 /usr/bin/chromium-browser
# Run the image.
CMD npm start
FROM node:current-alpine
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
USER root
WORKDIR /usr/src/app
COPY package*.json ./
RUN chmod 744 package-lock.json
RUN apk add chromium

# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install \
&& echo "Installed NPM packages:" \
&& (npm list --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version

# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./
ENV CRAWLEE_CHROME_EXECUTABLE_PATH=/usr/bin/chromium-browser
RUN chmod 744 /usr/bin/chromium-browser
# Run the image.
CMD npm start
Error:
ERROR PuppeteerCrawler: Request failed and reached maximum retries. Error: Failed to launch the browser process! spawn /root/.cache/puppeteer/chrome/linux-1095492/chrome-linux/chrome ENOENT
ERROR PuppeteerCrawler: Request failed and reached maximum retries. Error: Failed to launch the browser process! spawn /root/.cache/puppeteer/chrome/linux-1095492/chrome-linux/chrome ENOENT
fixed

Did you find this page helpful?