Giter VIP home page Giter VIP logo

docker-lemp's Introduction

docker-lemp

Docker local development environment with PHP, NGiNX, MySQL/MariaDB (LEMP stack)

Download and install Docker and docker-compose, on Arch Linux follow the wiki and also install docker-compose. On OSX and Windows use the official documentation.

Motivation

Why Docker? The "ticky-tacky" kind, so called docker "images"? Well, it's simple, because it's a shared/common environment (between colleagues, clients, etc.), in other words a common configuration or even better containers. To put it simply, in a collaborative culture you have the advantage of working together on the same machine (locally and sometimes offline) but in different offices/places! As they say in 2022 StackOverflow Survey and I totally agree ๐Ÿ‘ "better than chocolate cake", have fun!

Screenshot

On Ubuntu, install it from the official Docker repository (to ensure we get the latest version), do the following:

$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
$ sudo apt update
$ apt-cache policy docker-ce
$ sudo apt install docker-ce
$ sudo systemctl status docker
$ sudo usermod -aG docker ${USER}

Then logout (and login) or reboot to apply the new group membership

$ su - ${USER}

Check that your user is part of the group and view all docker parameters

$ id -nG
$ docker

Add other users (if you need to)

$ sudo usermod -aG docker some_username

To install Docker Compose, check the latest updated stable version (replace X.XX.X with the desired version)

$ sudo curl -L "https://github.com/docker/compose/releases/download/X.XX.X/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --version

Run docker-compose and check the ports

$ git clone [email protected]:ncklinux/docker-lemp.git
$ cd docker-lemp
$ docker-compose up -d
$ docker-compose ps
$ netstat -tupln

Test MariaDB root access with the password ncklinux_root and add some sample data localhost/mysql_connection_test.php

$ docker-compose exec mysql bash
$ mysql -u root -p
$ SHOW DATABASES;
$ USE test;
$ CREATE TABLE authors (id INT, name VARCHAR(20), email VARCHAR(20));
$ SHOW TABLES;
$ INSERT INTO authors (id,name,email) VALUES(1,"ncklinux1","[email protected]");
$ INSERT INTO authors (id,name,email) VALUES(1,"ncklinux2","[email protected]");
$ SELECT * FROM authors;

Screenshot Modify/copy your files in the public directory and refresh http://localhost on your browser (with F5 or Ctrl+F5). Also use docker-compose exec phpfpm bash to access the files on the container.

$ cd public
$ ls -la

Stop and remove all docker containers and images

$ docker ps -aq
$ docker stop $(docker ps -aq)
$ docker rm $(docker ps -aq)
$ docker rmi $(docker images -q)

Another way to remove all stopped containers

$ docker-compose ps
$ docker-compose stop
$ docker container prune
$ docker images
$ docker rmi mariadb nginx bitnami/php-fpm
$ docker ps && docker ps -a && docker images

Also, the command below removes all stopped containers, dangling images and unused networks. The command will prompt you to confirm the operation Are you sure you want to continue? [y/N], just type y

$ docker system prune

Check also the best practices for writing Dockerfiles

Lastly, you may need (but it is not necessary for this project) an account to Docker Hub, just in case, if you like to build your own images and push them up to Docker Hub.

Support

The above project has been tested/hosted on Arch Linux but there are no differences between distributions (only the Docker installation process differs e.g. Arch Linux provides Pacman, Ubuntu Apt etc), for reporting bugs, requesting features or better methods, it's best to open an issue. It's even better to accompany it with a Pull Request. ;)

License

GNU General Public License v3.0

Powered by

Alternative to Docker?

You could use Vagrant!

docker-lemp's People

Contributors

ncklinux avatar

Stargazers

 avatar

Watchers

 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.