M
M
mcavalon2022-02-08 17:14:32
macOS
mcavalon, 2022-02-08 17:14:32

How to get docker working on macOS Monterey (m1)?

Good afternoon.

For several days I have been struggling with the problem of raising the project in docker.

Configs:
MacOS Monterey (m1)
Docker version 20.10.12, build e91ed57
Docker Compose version v2.2.3
MySQL: 5.7
PHP: 7.4
Laravel 6

docker-compose.yml
version: "3"

services:
  webserver:
    build: 
      context: ./bin/webserver
    container_name: 'php'
    restart: 'always'
    ports:
      - "${HOST_MACHINE_UNSECURE_HOST_PORT}:80"
      - "${HOST_MACHINE_SECURE_HOST_PORT}:443"
    volumes: 
      - ./www:/var/www
      - ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/conf.d/pk.ini
      - ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
      - ${LOG_DIR-./logs/apache2}:/var/log/apache2
      - ./ssl:/etc/apache2/ssl

  mysql:
    platform: linux/x86_64
    build:
      context: "./bin/${DATABASE}"
    container_name: 'mysql'
    restart: 'always'
    ports:
      - "${HOST_MACHINE_MYSQL_PORT}:3306"
    volumes: 
      - ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
      - ${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}

  redis:
    container_name: 'redis'
    image: redis:latest
    ports:
      - "${HOST_MACHINE_REDIS_PORT}:6379"


Dockerfile
FROM php:7.4.2-apache-buster

# Surpresses debconf complaints of trying to install apt packages interactively
# https://github.com/moby/moby/issues/4032#issuecomment-192327844

ARG DEBIAN_FRONTEND=noninteractive

# Update
RUN apt-get -y update --fix-missing && \
    apt-get upgrade -y && \
    apt-get --no-install-recommends install -y apt-utils && \
    rm -rf /var/lib/apt/lists/*

# Install useful tools and install important libaries
RUN apt-get -y update && \
    apt-get -y --no-install-recommends install nano wget \
    dialog \
    libsqlite3-dev \
    libsqlite3-0 && \
    apt-get -y --no-install-recommends install default-mysql-client \
    zlib1g-dev \
    libzip-dev \
    libicu-dev && \
    apt-get -y --no-install-recommends install --fix-missing apt-utils \
    build-essential \
    git \
    curl \
    libonig-dev && \
    apt-get -y --no-install-recommends install --fix-missing libcurl4 \
    libcurl4-openssl-dev \
    zip \
    openssl && \
    rm -rf /var/lib/apt/lists/*

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Install node
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash && \
    apt-get -y update && \
    apt-get install -y nodejs

# Install redis
RUN pecl install redis-5.1.1 && \
    docker-php-ext-enable redis

# Install mongodb
RUN pecl install mongodb-1.10.0 && \
    docker-php-ext-enable mongodb

# Other PHP7 Extensions
RUN docker-php-ext-install pdo_mysql && \
    docker-php-ext-install pdo_sqlite && \
    docker-php-ext-install mysqli && \
    docker-php-ext-install curl && \
    docker-php-ext-install tokenizer && \
    docker-php-ext-install json && \
    docker-php-ext-install zip && \
    docker-php-ext-install -j$(nproc) intl && \
    docker-php-ext-install mbstring && \
    docker-php-ext-install gettext

# Install Freetype 
RUN apt-get -y update && \
    apt-get --no-install-recommends install -y libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev && \
    rm -rf /var/lib/apt/lists/* && \
    docker-php-ext-configure gd && \
    docker-php-ext-install gd

# Install soap
RUN apt-get -y update && apt-get -y --no-install-recommends install libxml2-dev
RUN docker-php-ext-install soap

# Enable apache modules
RUN a2enmod rewrite headers

# Enable ssl
RUN a2enmod ssl

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

# Cleanup
RUN rm -rf /usr/src/*


.env in Laravel
DB_HOST_READ=mysql
DB_HOST_WRITE=mysql
DB_DATABASE=pkdb
DB_USERNAME=user
DB_PASSWORD=secret


So that I don't set memory_limit in php.ini I always get the following error:
[Tue Feb 08 08:31:54.681854 2022] [php7:error] [pid 42] [client 192.168.48.1:58768] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 839680 bytes) in /var/www/app.siteurl.net/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php on line 50, referer: https://app.siteurl.net/admin/login
[Tue Feb 08 08:31:54.788122 2022] [php7:error] [pid 42] [client 192.168.48.1:58768] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 839680 bytes) in Unknown on line 0, referer: https://app.siteurl.net/admin/login


Maybe someone faced a similar problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question