Puppeteer in docker container: Chromium revision is not downloaded

I ran into this problem and I wanted to leave the simple solution. The reason it couldn't find my chrome install is that I had mounted my local volume into the container for testing. I use a mac, so the local npm install gave me the mac version of chromium. When that node_modules folder was mounted into the linux container, it expected to find the linux version which was not there.

To get around this, you need to exclude your node_modules folder when you're doing a volume mount into the container. I was able to do that by passing another volume parameter.

docker run -rm \
  --volume ~/$project:/dist/$project \
  --volume /dist/$project/node_modules

The docker volume I was using mapped the entire local code directory to the docker container's /usr/src/app directory.

This is great for allowing quick code updates during development.

However, it also overwrites the version of chromium previously installed on the docker container via the yarn install in the Dockerfile with the version of chromium installed on my machine via yarn install in the command line.

Each machine needs its own, correct, os-specific version of chromium. The docker container needs a linux-specific chromium (linux-515411), my laptop needs a mac-specific chromium (mac-508693). Simply running yarn install (or npm install) with puppeteer in your package.json will handle installing the correct version of chromium.

Previous project structure:

.
├── Dockerfile
├── README.md
└── code
    ├── index.js
    ├── package.json
    └── node_modules
        ├── lots of other node packages
        └── puppeteer
            ├── .local-chromium
            │     └── mac-508693 <--------good for macs, bad for linux!
            ├── package.json
            └── all the other puppeteer files

Partial Dockerfile

This is where the container gets its own version of .local-chromium:

FROM node:8

RUN apt-get update

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY code/package.json /usr/src/app
COPY code/index.js /usr/src/app

# install the necessary packages <------ including puppeteer, with the correct chromium
RUN yarn install

CMD npm run start:dev

Previous volumes from docker-compose.yml

This copies everything from the local ${REPO}/code to the docker container's /usr/src/app directory. Including the wrong version of chromium.

volumes:
    - ${REPO}/code:/usr/src/app:ro

Updated project structure:

.
├── Dockerfile
├── README.md
└── code
    ├── src
    │   ├── index.js
    │   └── package.json
    └── node_modules
        ├── lots of other node packages
        └── puppeteer
            ├── .local-chromium
            ├── package.json
            └── all the other puppeteer files

Updated docker volume maps the entire contents of the local ./code/src to the docker container's /usr/src/app. This does NOT include the node_modules directory:

volumes:
    - ${REPO}/code/src:/usr/src/app:ro