'Installing imagemagick in docker container

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?



Solution 1:[1]

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

Solution 2:[2]

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

Solution 3:[3]

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.

Solution 4:[4]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 benjifisher
Solution 3 vencedor
Solution 4 danday74