How to install Imagick in PHP Docker?

The PHP docker image is build from the source and hence the usual apt-get install php-imagick doesn’t work at all. This might be frustrating for you as most of the solutions have a version attached to it. However, I found a way to always have it updated. Here is how –

Dockerfile for Imagick

This is how docker file should look like:

FROM php:7.3-apache
RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN printf "\n" | pecl install imagick
RUN docker-php-ext-enable imagick

Build Output

....

configuration option "php_ini" is not set to php.ini location
You should add "extension=imagick.so" to php.ini
Removing intermediate container 1c032fba6d45
 ---> 517795f672ac
Step 4/4 : RUN docker-php-ext-enable imagick
 ---> Running in 976ecd4a9627
Removing intermediate container 976ecd4a9627
 ---> 4b978dd49756
Successfully built 4b978dd49756

Git Repositor and Docker

SpaceBox – Docker Development Box on SpaceVim

I have created SVIM which is a dockerized version of VIM. However, some of the most imporant plugins I was using is no longer maintained for VIM but are compatible and focussed on NVIM. Thus, I switched to SpaceVim. Despite there is an official Docker of SpaceVim, it is lacking the support of languages as required tools are missing in the docker particularly Go lang hints. Hence, I created my own version of SpaceVim and I ensured that all the stuff I use is working properly. If you are PHP developer, JavaScript developer, Golang Coder or even if you create simple HTMLs – you have everything you need. I haven’t focused on Java or alike line languages like scala or for that matter Objective C. This is ideally for the Web Developer and not for the Mobile App Developer. Though, feel free to send a PR. I am calling it SpaceBox – a dockerized SpaceVim

Why should you use SpaceBox?

How to use it?

alias vbox='docker run -ti -e TZ=Asia/Kolkata -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -e TMPDIR="/tmp/" -e TERM=xterm -e GIT_USERNAME="Your Name" -e GIT_EMAIL="YourEmail@Stealer.com"  --rm -v /etc/timezone:/etc/timezone:ro -v $HOME/tmp/:/tmp/ -v ~/.ssh:/home/spacevim/.ssh -v $(pwd):/home/spacevim/src varunbatrait/spacebox'

Docker Services For Development Infrastructure

Most of the web developers need at least three services running in their machine namely redis, mongo and mysql.

I have composed a simply docker-compose.yml file to run MySQL, MongoDB and Redis with Docker that too with a standard ports and authentication.

version: '3.2'
services:
    redis:
        image: redis:5.0.3
        restart: always
        network_mode: host
        ports:
            - 6379:6379
        command: redis-server --requirepass a_password
    mysql:
        image: mysql:5.7
        restart: always
        network_mode: host
        ports:
            - 3306:3306
        volumes:
            - type: bind
              source: ./mysql
              target: /var/lib/mysql
        environment:
            - MYSQL_ROOT_PASSWORD=a_password
        command: mysqld --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    mongodb:
        image: mongo:4.1.7-xenial
        restart: always
        environment:
          - MONGODB_USER="root"
          - MONGODB_DATABASE="some_db"
          - MONGODB_PASS="a_password"
          - MONGO_DATA_DIR=/data/db
          - MONGO_LOG_DIR=/dev/null
        volumes:
          - ./data/db:/data/db
        ports:
            - 27017:27017

Run

To run it, use following command:

docker-compose up -d