Automattic / Automattic/node-canvas
Canvas won't run in a docker container
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 1.2k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 1
Description
## Issue or Feature
- [x] If this is an issue with installation, I have read the [troubleshooting guide](https://github.com/Automattic/node-canvas/issues/1511).
I've been trying to get canvas to work in a docker container, running a discord bot. I can install canvas without issues, the problem is canvas won't run. Nor on node:20 nor node:20-alpine. Has anyone had this happen to them and possibly knows a solution to this? Here's the error I'm getting
```
obsidian-dev | Error: libjpeg.so.8: cannot open shared object file: No such file or directory
obsidian-dev | at Module._extensions..node (node:internal/modules/cjs/loader:1454:18)
obsidian-dev | at Object.nodeDevHook [as .node] (/usr/src/node_modules/ts-node-dev/lib/hook.js:63:13)
obsidian-dev | at Module.load (node:internal/modules/cjs/loader:1208:32)
obsidian-dev | at Function.Module._load (node:internal/modules/cjs/loader:1024:12)
obsidian-dev | at Module.require (node:internal/modules/cjs/loader:1233:19)
obsidian-dev | at require (node:internal/modules/helpers:179:18)
obsidian-dev | at Object. (/usr/src/node_modules/canvas/lib/bindings.js:3:18)
obsidian-dev | at Module._compile (node:internal/modules/cjs/loader:1358:14)
obsidian-dev | at Module._compile (/usr/src/node_modules/source-map-support/source-map-support.js:568:25)
obsidian-dev | at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
obsidian-dev | [ERROR] 14:04:23 Error: libjpeg.so.8: cannot open shared object file: No such file or directory
```
libjpeg8 is no longer part of debian nor alpine. I tried installing it but that didn't work either. Then I tried installing `libjpeg62-turbo` and create a symlink, but that didn't work either.
The code runs fine outside of my container (on my arch machine).
## Steps to Reproduce
Here's my docker container:
```Docker
# Base image with Node.js
FROM node:20 as base
# Create and set the working directory
RUN mkdir -p /usr/src
WORKDIR /usr/src
RUN apt-get update && apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
# Copy package.json and install dependencies
COPY package*.json ./
RUN npm install
# Copy the rest of the application code
COPY . .
# Production build
FROM base as production
ENV NODE_ENV=production
CMD ["npm", "run", "start"]
# Development build
FROM base as development
ENV NODE_ENV=development
CMD ["npm", "run", "dev"]
```
## Your Environment
* Version of node-canvas (output of `npm list canvas` or `yarn list canvas`): canvas@2.11.2
* Environment (e.g. node 20.9.0 on macOS 14.1.1): docker container, tried both images node:20 and node:20-alpine
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.