Puppeteer in docker container: Chromium revision is not downloaded
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:8RUN apt-get updateRUN mkdir -p /usr/src/appWORKDIR /usr/src/appCOPY code/package.json /usr/src/appCOPY code/index.js /usr/src/app# install the necessary packages <------ including puppeteer, with the correct chromiumRUN yarn installCMD 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
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
Hey guys please visit this link. This is quite helpful for you who want to launch headless puppeter inside docker container
https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
This is my project code structure
- config
- migrations
- models
- utils
- .dockerignorefile
- app.js
- docker-compose.yml
- Dockerfile
- package.json
Make sure you have install docker. Once installed you can follow these procedure
Run docker-compose up --build inside your docker directory
And this my repo regarding headless chrome inside docker