Code Monkey home page Code Monkey logo

docker-lemp's Introduction

docker-lemp

Do not use this LEMP in Production. For production, use adhocore/phpfpm then compose a stack using individual nginx, redis, mysql etc images.

adhocore/lemp is a minimal single container LEMP full stack for local development.

If you want to use PHP7.4 on LEMP stack then head over to adhocore/lemp:7.4.

It is quick jumpstart for onboarding you into docker based development.

The docker container adhocore/lemp is composed of:

Name Version Port
adminer 4.7.7 80
alpine 3.12 -
beanstalkd 1.11 11300
elasticsearch 6.4.3 9200,9300
mailcatcher 0.7.1 88
memcached 1.6.6 11211
MySQL* 5.7 3306
nginx 1.18.0 80
phalcon 4.0.0 -
PHP 8.0.0 9000
PostgreSQL 12.3 5432
rabbitmq 3.8.* 5672
redis 5.0.9 6379
swoole 4.4.12 -

*: It is actually MariaDB 10.4.13.

Usage

Install docker in your machine. Also recommended to install docker-compose.

# pull latest image
docker pull adhocore/lemp:8.0

# Go to your project root then run
docker run -p 8080:80 -p 8888:88 -v `pwd`:/var/www/html --name lemp -d adhocore/lemp:8.0

# In windows, you would use %cd% instead of `pwd`
docker run -p 8080:80 -p 8888:88 -v %cd%:/var/www/html --name lemp -d adhocore/lemp:8.0

# If you want to setup MySQL credentials, pass env vars
docker run -p 8080:80 -p 8888:88 -v `pwd`:/var/www/html \
  -e MYSQL_ROOT_PASSWORD=1234567890 -e MYSQL_DATABASE=appdb \
  -e MYSQL_USER=dbuser -e MYSQL_PASSWORD=123456 \
  --name lemp -d adhocore/lemp:8.0
  # for postgres you can pass in similar env as for mysql but with PGSQL_ prefix

After running container as above, you will be able to browse localhost:8080!

The database adminer will be available for mysql and postgres.

The mailcatcher will be available at localhost:8888 which displays mails in realtime.

Stop container

To stop the container, you would run:

docker stop lemp

(Re)Start container

You dont have to always do docker run as in above unless you removed or lost your lemp container.

Instead, you can just start when needed:

docker start lemp

PRO If you develop multiple apps, you can create multiple lemp containers with different names.

eg: docker run -p 8081:80 -v $(pwd):/var/www/html --name new-lemp -d adhocore/lemp:8.0

With Docker compose

Create a docker-compose.yml in your project root with contents something similar to:

# ./docker-compose.yml
version: '3'

services:
  app:
    image: adhocore/lemp:8.0
    # For different app you can use different names. (eg: )
    container_name: some-app
    volumes:
      - db_data:/var/lib/mysql
      # Here you can also volume php ini settings
      # - /path/to/zz-overrides:/usr/local/etc/php/conf.d/zz-overrides.ini
    ports:
      - 8080:80
    environment:
      MYSQL_ROOT_PASSWORD: supersecurepwd
      MYSQL_DATABASE: appdb
      MYSQL_USER: dbusr
      MYSQL_PASSWORD: securepwd
      # for postgres you can pass in similar env as for mysql but with PGSQL_ prefix

volumes:
  db_data: {}

Then all you gotta do is:

# To start
docker-compose up -d

# To stop
docker-compose stop

As you can see using compose is very neat, intuitive and easy. Plus you can already set the volumes and ports there, so you dont have to type in terminal.

MySQL Default credentials

  • root password: 1234567890 (if MYSQL_ROOT_PASSWORD is not passed)
  • user password: 123456 (if MYSQL_USER is passed but MYSQL_PASSWORD is not)

PgSQL Default credentials

  • postgres password: 1234567890 (if PGSQL_ROOT_PASSWORD is not passed)
  • user password: 123456 (if PGSQL_USER is passed but PGSQL_PASSWORD is not)

Accessing DB

In PHP app you can access MySQL db via PDO like so:

$db = new PDO(
    'mysql:host=127.0.0.1;port=3306;dbname=' . getenv('MYSQL_DATABASE'),
    getenv('MYSQL_USER'),
    getenv('MYSQL_PASSWORD')
);

You can access PgSQL db via PDO like so:

$pdb = new PDO(
    'pgsql:host=127.0.0.1;port=5432;dbname=' . getenv('PGSQL_DATABASE'),
    getenv('PGSQL_USER'),
    getenv('PGSQL_PASSWORD')
);

Nginx

URL rewrite is already enabled for you.

Either your app has public/ folder or not, the rewrite adapts automatically.

PHP

For available extensions, check adhocore/phpfpm#extension.

Testing mailcatcher

# open shell
docker exec -it lemp sh

# send test mail
echo "\n" | sendmail -S 0 test@localhost

Then you will see the new mail in realtime at http://localhost:8888.

Or you can check it in shell as well:

curl 0:88/messages

docker-lemp's People

Contributors

adhocore avatar

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.