23

I'm trying to use ImageMagick on my Ubuntu 14.04 server for resizing an image before uploading to s3. I'm running everything inside of a docker container that's being created by Wercker. The problem is I've already installed it on the server, and installed it in the Wercker build for the docker container, yet my EasyImage (nodejs library handling the resizing) is saying

 ImageMagick Not Found
 EasyImage requires ImageMagick to work. Install it from http://www.imagemagick.org/script/binary-release.php.

This is the command I have in my Wercker file to install imagemagick

sudo apt-get update -y && sudo apt-get install -y imagemagick php5-imagick

I've also used

sudo apt-get update -y && sudo apt-get install -y imagemagick

, but neither seem to work. Am I missing something to get ImageMagick working inside of a docker container?

Cortwave
  • 4,747
  • 2
  • 25
  • 42
Thomas Horner
  • 283
  • 1
  • 2
  • 11
  • Can we have a look at your (or some of your) wercker.yml ? Maybe there's a command in there or an ordering issue that's causing EasyImage not to find ImageMagick. – ocean Jun 24 '16 at 06:54
  • Please refer this [example](https://stackoverflow.com/a/70504590/6503329) for assistance. – Shreyesh Desai Dec 28 '21 at 08:43

5 Answers5

12

You need to install imagick using pecl and extension to enable imagick in php. The following command worked for me:

RUN apt-get update && apt-get install -y \
    imagemagick libmagickwand-dev --no-install-recommends \
    && pecl install imagick \
    && docker-php-ext-enable imagick
benjifisher
  • 5,054
  • 16
  • 18
Rakesh Sadaka
  • 139
  • 1
  • 3
  • I would recommend piping a new line into your `pecl install imagick` command, so that docker build doesn't fail. This is how I did it: `printf “\n” | pecl install imagick` – Tony Langworthy Jan 01 '23 at 15:08
11

i met problem with imagemagick in docker container too. I share a part of my docker config. When i tested into docker container what's goes wrong, i see error from imagemagick about lost fonts. If you use lightweight version of smth images like linux-alpine or smth else, your images cannot have any important tools like your local machine or VM. Of course you need to install it in docker container, not in your vm on server

Install of imagemagic in docker very simple: apk --update add imagemagick

A part of my docker file. I install some important font, imagemagic work with it great. And yet it can resolve another problem, because i have this error when try to use imagemagick in docker

Stream yields empty buffer

# the first thing we specify in a Dockerfile is the base image
FROM keymetrics/pm2:latest-alpine

RUN yarn global add pm2@latest

# Install image preview generator tools
RUN apk add --no-cache file
RUN apk --update add imagemagick

# Install fonts
RUN apk --no-cache add msttcorefonts-installer fontconfig && \
 update-ms-fonts && \
 fc-cache -f
4

For me, this code worked:

RUN set -ex \
    && apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS imagemagick-dev libtool \
    && export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
    && pecl install imagick-3.4.3 \
    && docker-php-ext-enable imagick \
    && apk add --no-cache --virtual .imagick-runtime-deps imagemagick \
    && apk del .phpize-deps

it installs the imagick trough pecl install then enables the php ext.

I found the solution here.

vencedor
  • 663
  • 7
  • 9
2

I use these instructions to install a given version of ImageMagick including all dependencies. Processing time: 60 seconds.

You may omit the 'alien' part if your base image supports rpm package manager.

FROM debian:bullseye-slim
ARG DEBIAN_FRONTEND=noninteractive
RUN IMV='7.1.0-37' && \
    BUILD_TOOLS='alien' && \
    apt-get update && \
    apt-get install -y ${BUILD_TOOLS}  && \
    mkdir -p /tmp/imagemagick && \
    cd /tmp/imagemagick && \
    curl -o ImageMagick-${IMV}.x86_64.rpm -L "https://download.imagemagick.org/ImageMagick/download/linux/CentOS/x86_64/ImageMagick-${IMV}.x86_64.rpm" && \
    alien -ik ImageMagick-${IMV}.x86_64.rpm && \
    curl -o ImageMagick-libs-${IMV}.x86_64.rpm -L "https://download.imagemagick.org/ImageMagick/download/linux/CentOS/x86_64/ImageMagick-libs-${IMV}.x86_64.rpm" && \
    alien -ik ImageMagick-libs-${IMV}.x86_64.rpm && \
    apt-get purge -y ${BUILD_TOOLS} && \
    cd / && rm -rf /tmp/imagemagick && \
    apt-get -y purge man && \
    apt-get -y purge && \
    apt-get -y clean autoclean && \
    apt-get -y autoremove && \
    rm -rf /var/lib/apt/{apt,dpkg,cache,log,lists}/*
regnete
  • 136
  • 3
1

I would use Image Magick Easy Install (IMEI) to install imagemagick within a parent docker image. Here's my Dockerfile which does just that.

The purpose of using a parent image is to reduce docker build times since IMEI takes a while to run. IMEI is very professional and will ensure imagemagick is up to date and has all the necessary dependencies installed (e.g. for working with HEIF files, etc)

My parent image also installs ffmpeg but you can create your own parent image and tailor it to your needs.

Then just create your child Dockerfile using:

FROM parent-image

example:

FROM danday74/ubuntu18-ffmpeg4-imagemagick7
danday74
  • 52,471
  • 49
  • 232
  • 283