aripalo/gatsby-docker

gatsby-plugin-sharp error

Closed this issue · 2 comments

Hi, I tried to run my gatsby project that uses gatsby-plugin-sharp, I typed in:

docker run -it --rm -v $(pwd)/site:/site -p 8000:8000 aripalo/gatsby-docker develop

but I'm getting following error:

Error: Error loading shared library /site/node_modules/sharp/build/Release/sharp.node: Exec format error

Everything is working fine when I'm starting a new project without mentioned plugin. Does anyone know what I'm doing wrong?

I just started to run this docker image, and noticed my terminal output states the following:

Error: 'linux-x64' binaries cannot be used on the 'linuxmusl-x64' platform. Please remove the 'node_modules/sharp/vendor' directory an d run 'npm install'.

error GraphQL Error Unknown field childImageSharp on type File

/site/src/components/image.js
21:11 error Cannot query field "childImageSharp" on type "File" graphql/template-strings

So it might be due to the first error about musl(alpine linux as base I assume). Changing to another base image that doesn't use musl but libc like most would fix that or recompiling the binary modules. Alpine would have been chosen for achieving a small filesize in the docker image file.

EDIT: Nevermind, might have been something with the docker image or from me running npm install for a new package I added on my host(out of the container).

No issues with the binaries they're compiled at install, I was installing them on Linux host(libc) vs in the container(musl).

Deleted the node_modules directory and went into my container docker exec -it container_name_here /bin/sh to run yarn to reinstall everything. Restarted the container, it mentioned something about one or more plugins having changed so it deleted the cache folder.

There is two deprecations mentioned though, perhaps due to age of docker image and files it uses?, not sure:

boundActionCreators is deprecated. Please use actions instead. For migration instructions, see https://gatsby.app/boundActionCreators

pathContext is deprecated. Please use pageContext instead. For migration instructions, see https://gatsby.app/pathContext

The sharp plugin depends on a bunch of system libraries not shipping with node 9.5 alpine image.
As this docker image doesn't install any additional dependencies and hasn't been updated in 2 years, that's to be expected.
You're better off copying the entry.sh file and creating your own docker container based on a more recent nodejs build and installing the required libGL version.