Celeb Glow
updates | March 05, 2026

ImageMagick installation in Docker Alpine

So I have this Dockerfile that attempts to install ImageMagick the following way:

FROM ruby:2.4-alpine
...
RUN apk --update add imagemagick
...

The point is that the container doesn't recognizes the file utility (for content-type detection).

Local environment (Mac OSX, installed imagemagick with brew):

> file --version
file-5.25
magic file from /usr/share/file/magic
> convert --version
Version: ImageMagick 6.9.9-5 Q16 x86_64 2017-08-03
Copyright: © 1999-2017 ImageMagick Studio LLC
License:
Features: Cipher DPC Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib

Docker Alpine container (accessed to the shell using docker exec -it CONTAINER_ID):

> file --version
sh: file: not found
> convert --version
Version: ImageMagick 6.9.5-9 Q16 x86_64 2016-10-21
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License:
Features: Cipher Modules
Delegates (built-in): fontconfig freetype gslib jng jpeg lcms ltdl png ps tiff webp zlib

Also tried installing imagemagick-dev by itself, and both of them combined without any luck (shouldn't make a difference since the first one is a dependency of the latter, I guess).

The question is, how can I install this in the Alpine container? I think I'm missing something but can't figure it out.

By the way, I can't rely on another function other than file for content-type detection since I'm using a framework that explicitly uses this.

1 Answer

Here's a similar Q/A that helped me on stackoverflow:
imagemagick installation in docker alpine

The file utility is not part of ImageMagick, it is a standard utility. You can read more about it on wikipedia:
File (command).

On Alpine Linux, you can install it with apk add --no-cache file. As shown in the following terminal session:

/ # file /etc/group
/bin/sh: file: not found
/ # apk add --no-cache file
fetch
fetch
/APKINDEX.tar.gz
(1/2) Installing libmagic (5.32-r0)
(2/2) Installing file (5.32-r0)
Executing busybox-1.26.2-r5.trigger
OK: 9 MiB in 13 packages
/ # file /etc/group
/etc/group: ASCII text
/ #
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy