W
Wasp2mo ago
NEROX

Install deps on docker

I'm trying to use just the npm package https://www.npmjs.com/package/pdf2pic But it gives error because of the prerequisites (graphicsmagick, ghostscript) They have a guide to do it: https://github.com/yakovmeister/pdf2image/blob/HEAD/docs/gm-installation.md:
# GraphicsMagick installation

This guide will help you install the required dependencies to get started!


## Linux (Debian based)

For linux users, you can run the following commands on your terminal.


$ sudo apt-get update
$ sudo apt-get install ghostscript
$ sudo apt-get install graphicsmagick


Once everything is installed, the library should work as expected.
# GraphicsMagick installation

This guide will help you install the required dependencies to get started!


## Linux (Debian based)

For linux users, you can run the following commands on your terminal.


$ sudo apt-get update
$ sudo apt-get install ghostscript
$ sudo apt-get install graphicsmagick


Once everything is installed, the library should work as expected.
But with Wasp and Docker, this would be... how?
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @NEROX. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To install system dependencies like graphicsmagick and ghostscript for use with an npm package (such as pdf2pic) in a Wasp app running in Docker, you need to modify your Dockerfile to include the necessary installation commands. While the knowledge sources do not provide a ready-made Dockerfile for this exact scenario, they do show examples of customizing Dockerfiles for Wasp apps, including installing system packages using commands like RUN apk add ... for Alpine-based images or RUN apt-get install ... for Debian-based images. You can adapt these examples to install your required dependencies. Here’s how you might do it, based on the patterns shown in the sources: 1. Locate or create your Dockerfile: Wasp uses Dockerfiles for server builds, and you can customize them as needed. For example, in the RFC: Customizing the default server Dockerfile discussion, system packages are installed in the build stage using RUN commands. 2. Add the required system dependencies: If your Docker base image is Debian-based, you can use the following commands in your Dockerfile:
FROM node:18-slim

# Install system dependencies
RUN apt-get update && \
apt-get install -y graphicsmagick ghostscript && \
rm -rf /var/lib/apt/lists/*

# ...rest of your Dockerfile (copy app files, install npm packages, etc.)
FROM node:18-slim

# Install system dependencies
RUN apt-get update && \
apt-get install -y graphicsmagick ghostscript && \
rm -rf /var/lib/apt/lists/*

# ...rest of your Dockerfile (copy app files, install npm packages, etc.)
If you are using Alpine Linux as your base image (as in some Wasp examples), the equivalent would be:
FROM node:18-alpine

# Install system dependencies
RUN apk add --no-cache graphicsmagick ghostscript

# ...rest of your Dockerfile
FROM node:18-alpine

# Install system dependencies
RUN apk add --no-cache graphicsmagick ghostscript

# ...rest of your Dockerfile
3. Continue with the rest of your Dockerfile as per Wasp’s requirements (copying files, installing npm packages, etc.). This approach is consistent with how Wasp expects you to customize Dockerfiles for additional system dependencies, as shown in the Dockerfile customization example. Note: The knowledge sources do not provide a full, official Wasp Dockerfile template for this use case, but they do confirm that you can and should install system dependencies in your Dockerfile using standard Docker practices. If you need to override or extend the default Dockerfile, you can append your custom instructions as shown in the linked RFC and discussion. This is the recommended way to ensure your app has all the system-level dependencies it needs when running in Docker with Wasp. For more details on customizing Dockerfiles in Wasp, see the discussion and examples here: RFC: Customizing the default server Dockerfile. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Carlos
Carlos4w ago
As we say in the Docker docs, you can check the Dockerfile with wasp dockerfile and create your custom one that will get appended to the default one (and thus can override it too). In short, if you're using the latest version of Wasp, you can just create a Dockerfile in your project with the following contents:
FROM node:22 AS base

RUN apt-get update -y && apt-get install -y ghostscript ghostscript
FROM node:22 AS base

RUN apt-get update -y && apt-get install -y ghostscript ghostscript
that should override our default base image with one with your dependencies installed is that useful @NEROX?
NEROX
NEROXOP4w ago
I think yes, I want to deploy changes today so I will see😆

Did you find this page helpful?