How to install mcrypt on Docker
Asked Answered
M

2

10

I have a Docker Container with Phalcon3 and php 7. I am trying to install the php extension Mcrypt without luck.

If I do ssh to the container, and execute:

apt-get update
apt-get install php7.0-mcrypt  

I get the following:

E: Unable to locate package php7.0-mcrypt
E: Couldn't find any package by regex 'php7.0-mcrypt'

Is there a way to get it installed?

Mud answered 8/11, 2017 at 13:47 Comment(4)
you should always begin with a apt-get update so try something along the lines of apt-get update && apt-get install -y php7.0-mcrypt the update first is necessary because you may use an OS (ubuntu, Debian or such) that has had many updates since its arrival. By the way, sudo is not necessary, you are root unless you do USER myuserHartnett
have a look at hub.docker.com/r/phpdocker/phpdocker/~/dockerfile (and the line FROM php:7.1-fpm is built on Debian)Hartnett
@Hartnett Sorry, yes I do apt-get update, and you are right sudo is not necesary in fact it complains about it. I updated the commands. Also Im traying to modify an existing container, not creating a new one, as you recommend on your second comment.Mud
Post the Dockerfile, it will be simplerHartnett
G
17

Lets look at official manual for php docker image Section PHP Core Extensions

For example, if you want to have a PHP-FPM image with iconv, mcrypt and gd extensions, you can inherit the base image that you like, and write your own Dockerfile like this:

FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

Rember, you must install dependencies for your extensions manually. If an extension needs custom configure arguments, you can use the docker-php-ext-configure script like this example. There is no need to run docker-php-source manually in this case, since that is handled by the configure and install scripts.

Greenhead answered 8/11, 2017 at 15:51 Comment(1)
Thank you that was great help. You can also ssh on the container and execute that same command: apt-get update && apt-get install -y \ libfreetype6-dev \ libjpeg62-turbo-dev \ libmcrypt-dev \ libpng-dev \ && docker-php-ext-install -j$(nproc) iconv mcrypt \ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install -j$(nproc) gdMud
L
30

From PHP manual:

This extension has been moved to the » PECL repository and is no longer bundled with PHP as of PHP 7.4.0.

So in your Dockerfile you have to:

RUN apt-get install libmcrypt-dev
RUN pecl install mcrypt-1.0.4 && docker-php-ext-enable mcrypt
Lazar answered 25/11, 2018 at 9:17 Comment(1)
Seems to work, but under Lando not completely. Or do I need add something there? #54753314Once
G
17

Lets look at official manual for php docker image Section PHP Core Extensions

For example, if you want to have a PHP-FPM image with iconv, mcrypt and gd extensions, you can inherit the base image that you like, and write your own Dockerfile like this:

FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

Rember, you must install dependencies for your extensions manually. If an extension needs custom configure arguments, you can use the docker-php-ext-configure script like this example. There is no need to run docker-php-source manually in this case, since that is handled by the configure and install scripts.

Greenhead answered 8/11, 2017 at 15:51 Comment(1)
Thank you that was great help. You can also ssh on the container and execute that same command: apt-get update && apt-get install -y \ libfreetype6-dev \ libjpeg62-turbo-dev \ libmcrypt-dev \ libpng-dev \ && docker-php-ext-install -j$(nproc) iconv mcrypt \ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install -j$(nproc) gdMud

© 2022 - 2024 — McMap. All rights reserved.