Code Monkey home page Code Monkey logo

docker-compose-laravel-alpine-for-mac-m1's Introduction

Docker-compose-laravel-alpine-for-mac-m1

A pretty simplified Docker Compose workflow that sets up a LNMP network of containers for local Laravel development on Mac M1.

You can modify the version of the images in the file "docker-compose.yml" or the Dockfile for the specific needs.

The following are built for our web server, with their exposed ports detailed:

  • nginx:stable-alpine - :80
  • mysql/mysql-server:latest-aarch64 - :3306
  • php:7.4.16-fpm-alpine3.13 - :9000
  • redis:alpine - :6379

The images are minimized as much as possible:

  • docker_php 135MB
  • redis 28.1MB
  • nginx 22.1MB
  • mysql/mysql-server 489MB

Prerequisites

To get started, make sure you have Docker installed on your system, and then clone this repository.

For the user of Mac M1, please follow Docker Desktop for Apple Silicon

Quick start

Step 1 - Spin up the containers for the web server

Navigate in your terminal to the directory you cloned this, and spin up the containers for the web server by running :

  • docker-compose up -d --build

Optional:

up without building,just run:

  • docker-compose up -d

Stops containers and removes containers, networks, volumes, and images created by up . By default, the only things removed are: Containers for services defined in the Compose file.

  • docker-compose down

Stop the container,"php" is the name of the container

  • docker-compose stop php

Start the containers,"php" is the name of the container

  • docker-compose start php

Step 2 - Get your Laravel project added in

follow the steps from the wwwroot/README.md file to get your Laravel project added in (or create a new blank one).

The usage of the project

PHP Service (composer included)

  • Accessing the Container Shell

    docker exec -it php sh
    
  • The mapped directory the service container for php

      volumes:
        - ./wwwroot:/var/www
        - ./php/php.ini:/usr/local/etc/php/php.ini
    
  • Composer install

    docker exec -w /var/www/your-site-root php composer install
    
  • Laravel: php artisan

    docker exec -w /var/www/your-site-root php php artisan serve
    docker exec -w /var/www/your-site-root php artisan migrate
    

The list of php extensions in the project

  • bcmath
  • gd
  • imap
  • intl
  • memcached
  • mysqlnd
  • pcntl
  • pdo_mysql
  • redis
  • tidy
  • Zend OPcache
  • zip
  • zlib
  • xdebug

Nginx Service

  • Accessing the Container Shell
      docker exec -it nginx  sh
    
  • The mapped directory the service container for nginx
      volumes:
        - ./wwwroot:/var/www
        - ./nginx/conf.d/:/etc/nginx/conf.d/
        - ./nginx/log:/var/log/nginx
    

MySQL Service

  • Mysql Client: Default password :12345678

    docker exec -it mysql mysql -uroot -p
    
  • The mapped directory the service container for mysql

    volumes:
        - mysqldata:/var/lib/mysql      
        - ./mysql/my.cnf:/etc/mysql/my.cnf 
    
  • Starting with MySQL 8 you no longer can (implicitly) create a user using the GRANT command. Use CREATE USER instead, followed by the GRANT statement

    mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'PASSWORD';
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
    mysql> FLUSH PRIVILEGES;
    

    Caution: about the security risks about WITH GRANT OPTION, see: Grant all privileges on database

  • Now, you can use any MySQL Client program to connect with MySQL Server,running on the container

    HOST:127.0.0.1
    PORT:3306
    USER:root
    PASSWORD:12345678 
    

Redis Service

  • Redis Client: Default password :(empty)
    docker exec -it redis redis-cli
    
  • The mapped directory the service container for redis
    volumes:
      - redisdata:/data
      - ./redis/conf:/usr/local/etc/redis
      - ./redis/log:/log   
    

docker-compose-laravel-alpine-for-mac-m1's People

Contributors

vgocoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-compose-laravel-alpine-for-mac-m1's Issues

Can't get it to work

Hi, thanks for preparing this repo!

I'm trying to get things to work under MacOS Monterey 12.0.1, but it's not working for me.

I've followed all the steps outlined in the readme and can see all four containers (mysql, redis, php and nginx) up and running in Docker Desktop. I can connect over CLI to all four of them without a problem, but I run into these issues:

  1. To test, I have placed my own index.html file in /wwwroot, but when I surf to http://localhost/, I get a generic 'Welcome to nginx!' page instead of the code I placed into /wwwroot. I placed the files in /wwwroot on the host machine, not within the container. I'd expect nginx to pick that up but I might be missing something.
  2. The docker-compose file indicates that the nginx container also exposes ports 443, 8000 and 8080, but when I surf to those my browser complains that the server dropped the connection (I am guessing this might be expected behavior)
  3. When I try to connect to the MySQL server using Sequel Ace, using 127.0.0.1 as server and 3306 as the port, I can't establish the connection. The message I get is: Host '172.18.0.1' is not allowed to connect to this MySQL server. I don't understand where that IP address comes from and why I can't connect to the MySQL database from my host system; I'm assuming that the post is exposed for that reason but maybe I'm misunderstanding.

I am probably running into these issues due to a lack of knowledge, if you could tell me how to proceed to get this working that'd be awesome. I'd be glad to supply further details if required.

Thanks!

How to install redis and xdebug extension?

failed to solve: executor failed running [/bin/sh -c apk add --no-cache libmemcached && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS libmemcached-dev zlib-dev && pecl redis-5.3.7.tgz xdebug-3.1.6.tgz && docker-php-ext-enable redis xdebug && rm -rf /tmp/pear && apk del -f .build-deps]: exit code: 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.