Coder Social home page Coder Social logo

narendrapsgim / docker-tutorial Goto Github PK

View Code? Open in Web Editor NEW

This project forked from osteel/docker-tutorial

0.0 1.0 1.0 5.74 MB

Companion repository for a tutorial series about using Docker locally for web development

Home Page: https://tech.osteel.me/posts/docker-for-local-web-development-introduction-why-should-you-care

License: MIT License

PHP 94.11% Dockerfile 3.98% Shell 1.91%

docker-tutorial's Introduction

Docker for local web development, part 1: a basic LEMP stack

This repository accompanies a tutorial series about leveraging Docker for local web development.

The current branch covers part 1 of the series, which is about setting up a basic LEMP stack with Docker Compose. Please refer to the full article for a detailed explanation.

Content

This branch contains a basic LEMP stack running on Docker and orchestrated by Docker Compose, including:

  • A container for Nginx;
  • A container for PHP-FPM;
  • A container for MySQL;
  • A container for phpMyAdmin;
  • A volume to persist MySQL data.

Prerequisites

Make sure Docker Desktop for Mac or PC is installed and running, or head over here if you are a Linux user. You will also need a terminal running Git.

This setup also uses localhost's port 80, so make sure it is available.

Directions of use

Add the following domain to your machine's hosts file:

127.0.0.1 php.test

Clone the repository and change the current directory for the project's root:

$ git clone [email protected]:osteel/docker-tutorial.git
$ cd docker-tutorial

Copy .env.example to .env:

$ cp .env.example .env

Run the following command:

$ docker-compose up -d

This may take a little bit of time, as some Docker images might need downloading.

Once the script is done, visit php.test.

Explanation

The images used by the setup are listed and configured in docker-compose.yml.

When building and starting the containers based on the images for the first time, a MySQL database named demo is automatically created (you can pick a different name in the MySQL service's description in docker-compose.yml).

A minimalist Nginx configuration for the PHP application is also copied over to Nginx's container, making it available at php.test.

The src/ directory containing the application is mounted onto both Nginx's and the application's containers, meaning any update to the code is immediately available upon refreshing the page, without having to rebuild any container.

The database data is persisted in its own local directory through the volume mysqldata, which is mounted onto MySQL's container. A phpMyAdmin interface is available at localhost:8080 (the database credentials are root / root).

Please refer to the full article for a detailed explanation.

Cleaning up

To stop the containers:

$ docker-compose stop

To destroy the containers:

$ docker-compose down

To destroy the containers and the associated volumes:

$ docker-compose down -v

To remove everything, including images and orphan containers:

$ docker-compose down -v --rmi all --remove-orphans

docker-tutorial's People

Contributors

osteel avatar

Watchers

 avatar

Forkers

muskanmahajan37

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.