Adding mbstring to docker image for laravel 5 app

SamBremner picture SamBremner · May 26, 2017 · Viewed 7.3k times · Source

I am new to docker and I'm trying to set it up in order to run with Laravel 5.1. I am currently getting the following error

Call to undefined function Illuminate\Foundation\Bootstrap\mb_internal_encoding() in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php:43

I believe this is because the mbstring php extention is not installed. I have tried to add php-mbstring to the Docker file but it doesn't seem to be working.

Here is my full Docker file

FROM php:5.6.30-fpm

    RUN apt-get update && apt-get install -y libmcrypt-dev \
        mysql-client libmagickwand-dev --no-install-recommends \
        && pecl install imagick \
        && docker-php-ext-install mcrypt pdo_mysql \
        && docker-php-ext-install php-mbstring 

I am then running sudo docker compose up from the application folder. This does not seem to be resolving the error though. How do I know if the extensions are being installed properly?

EDIT: I have included the docker-compose.yml file below

version: '2'
services:

  # The Application
  app:
    build:
      context: ./
      dockerfile: app.dockerfile
    working_dir: /var/www
    volumes:
      - ./:/var/www
    environment:
      - "DB_PORT=3306"
      - "DB_HOST=database"

  # The Web Server
  web:
    build:
      context: ./
      dockerfile: web.dockerfile
    working_dir: /var/www
    volumes_from:
      - app
    ports:
      - 8080:80

  # The Database
  database:
    image: mysql:5.6
    volumes:
      - dbdata:/var/lib/mysql
    environment:
      - "MYSQL_DATABASE=homestead"
      - "MYSQL_USER=homestead"
      - "MYSQL_PASSWORD=secret"
      - "MYSQL_ROOT_PASSWORD=secret"
    ports:
        - "33061:3306"

volumes:
  dbdata:

Answer

Leonardo Prado picture Leonardo Prado · May 26, 2017

Remove the php- prefix and it should work fine. You can also run it on the previous docker-php-ext-install command:

docker-php-ext-install mcrypt pdo_mysql mbstring