Home > Mobile >  Docker environment for PHP Framework from scratch
Docker environment for PHP Framework from scratch

Time:10-12

I need help to create my development environment in docker I have several errors implement this stack and I do not achieve my goal. I'm looking to get that working; Not Alternatives or Opinions.

I will explain and share everything I am trying

  1. Software used:

Windows 10 as Host.
Laragon (Nginx for reverse proxy)
Docker Desktop last Updated.

  1. Diagram estructure:

Diagram //need rep to public image.

  1. hosts file in windows System:
    127.0.0.1 minus.dok www.minus.dok
    127.0.0.1 phpmyadmin.dok www.phpmyadmin.dok
  1. Reverse Proxy in nginx file config:
server {
    server_name minus.dock;
    server_alias www.minus.dock;

    location / {
        proxy_pass localhost:8008;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout       5000;
        proxy_send_timeout          5000;
        proxy_read_timeout          5000;
        send_timeout                5000;
        fastcgi_send_timeout        5000;
        fastcgi_read_timeout        5000;
    }
}
  1. Project File Structure:
Minos
│   composer.json
│   composer.lock
│   docker-compose.yml    //docker-compose yml file
│   Dockerfile            //Dockerfile
│
├───conf-example          //for example files
│       apache.conf
│
├───envlog                //for Error server and PHP logs
├───public                //public folder
│
└───vendor
    │   autoload.php
    │
    ├───composer
    │       autoload_classmap.php
    │       autoload_namespaces.php
    │       autoload_psr4.php
    │       autoload_real.php
    │       autoload_static.php
    │       ClassLoader.php
    │       installed.json
    │       installed.php
    │       InstalledVersions.php
    │       LICENSE
    │       platform_check.php
    │
    └───phpmailer
        └───phpmailer
            │   COMMITMENT
            │   composer.json
            │   get_oauth_token.php
            │   LICENSE
            │   README.md
            │   SECURITY.md
            │   VERSION
            │
            ├───language
            │       phpmailer.lang-es.php
            │
            └───src
                    Exception.php
                    OAuth.php
                    OAuthTokenProvider.php
                    PHPMailer.php
                    POP3.php
                    SMTP.php
  1. Content of apache.conf for docker:
<VirtualHost *:80>
    #uri
    ServerName minus.dok
    ServerAlias *.minus.dok
    
    #Server Contact 
    ServerAdmin [email protected]
    
    #Server Config
    DirectoryIndex index.php
    DocumentRoot /var/www/public
    
    #Error Log
    ErrorLog /var/www/envlog/apache-error.log
    CustomLog /var/www/envlog/apache-access.log combined
    php_value error_log /var/www/envlog/php-error.log
    
    #Server Default Access
    <Directory /var/www/public>
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
  1. Content of docker-composer.yml for docker:
version: "3.8"
services:
  app:
    container_name: 'minos-php'
    restart: always
    build:
      context: ./public
      dockerfile: Dockerfile
    ports:
      - "8008:80"
    volumes:
      - ./public:/var/www/html/
      - .:/var/www
    depends_on:
      - mysql
    links:
      - mysql
  mysql:
    container_name: 'minos-mysql'
    image: arm64v8/mysql:oracle
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
      - mysql-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "33060:3306"
volumes:
  mysql-data:
  1. Content of Dockerfile for docker:
FROM ubuntu:22.04
LABEL maintainer="ChaosEmperorDragonEnvoyoftheEnd"
LABEL version="1.0.0"

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV DATE_TIMEZONE UTC
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    git \
    mysql-client \
    nano \
    unzip \
    wget \
    zip \
    apache2 \
    libapache2-mod-php \
    libmcrypt-dev \
    php \
    php-cli \
    php-gd \
    php-common \
    php-curl \
    php-imap \
    php-intl \
    php-json \
    php-mailparse \
    php-mbstring \
    php-mysql \
    php-pear \
    php-readline \
    php-soap \
    php-xml \
    php-xmlrpc \
    php-zip \
    php-bz2 \
    php-dba \
    php-ldap \
    php-dev \
    php-memcached \
    php-xdebug \
    cron \
    locales \
 && rm -rf /var/lib/apt/lists/*

RUN a2enmod rewrite

# Setup project folder
COPY public /var/www
RUN chown -R www-data:www-data /var/www
RUN chmod -R 0775 /var/www

# Configure apache
RUN a2enmod rewrite ssl
ADD conf-example/apache.conf /etc/apache2/sites-enabled/000-default.conf

# Configure PHP
RUN echo 'apc.enable_cli=1' >>  /etc/php/8.1/cli/php.ini

RUN echo 'max_execution_time = 9999' >> /etc/php/8.1/cli/php.ini
RUN echo 'memory_limit = 2G' >> /etc/php/8.1/cli/php.ini
RUN echo 'post_max_size = 2G' >> /etc/php/8.1/cli/php.ini
RUN echo 'max_input_vars = 2000' >> /etc/php/8.1/cli/php.ini
RUN echo 'upload_max_filesize = 2G' >> /etc/php/8.1/cli/php.ini
RUN echo 'display_errors = on' >> /etc/php/8.1/cli/php.ini

# Setup for testing
RUN locale-gen es_ES.UTF-8

RUN apt-get clean

Problem List:

  1. when i try to run this first code to build and take up the docker server:
docker compose up -d --build

get this error:

failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount4160904659/Dockerfile: no such file or directory

I run this: docker version and get:

Client:
 Cloud integration: v1.0.29
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:09:02 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.12.0 (85629)
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:23 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

How can i solve this error?

CodePudding user response:

Your context is wrong. Change it in the docker-compose.yml like so:

version: "3.8"
services:
  app:
    container_name: 'minos-php'
    restart: always
    build:
      context: .
      dockerfile: Dockerfile
  • Related