Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 890
Thomas Horner Avatar asked Apr 11 '16 18:04

Thomas Horner


3 Answers

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
like image 83
Виктор Могилевский Avatar answered Sep 23 '22 16:09

Виктор Могилевский


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
like image 41
Rakesh Sadaka Avatar answered Sep 19 '22 16:09

Rakesh Sadaka


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.

like image 2
vencedor Avatar answered Sep 21 '22 16:09

vencedor