GithubHelp home page GithubHelp logo

osteel / docker-tutorial Goto Github PK

View Code? Open in Web Editor NEW
160.0 160.0 56.0 5.81 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 95.95% Dockerfile 4.05%
docker docker-compose laravel php webdevelopment

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 philintv avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-tutorial's Issues

phpmyadmin.test doesnt seem to work with https...

I came across the error right after we installed the certificates...
when i entered phpmyadmin.test it was showing up as not secured.

changed the server_name to phpmyadmin.demo.test and restarted the container...

Works like it should work now :)

hope this helps out some others

Slackbot + Docker + ngrok results in Dispatch_failed

Hi @osteel, I wanted some inputs from you regarding Docker + ngrok as I am stuck and don't know how to proceed further.

Tl;Dr Docker running in one terminal, fails to listen/recognize ngrok's url running on another terminal. How to make Docker listen to ngrok?

Running the slackbot (built in python + flask) within PyCharm works fine, as in commands are executed and payloads/modals are being sent received. And so does running the command gunicorn --bind 0.0.0.0:5000 wsgi:flaskApp -w 4 within PyCharm's termnal (Please note, ngrok is running on mac's terminal via ./ngrok http 5000). The url in "Interactivity & Shortcuts" AND "Slash Commands" both point to https://...ngrok.io/slack/events. Again, the app, the commands, ngrok, everything works fine.

But when I move the slack app to within Docker and start Docker up with docker-compose up --build which in turns runs ENTRYPOINT ["gunicorn", "--bind", "0.0.0.0:5000", "wsgi:flaskApp", "--workers", "4"], the slackbot fails with dispatch_failed when a command is executed and ngrok terminal shows 502 Bad Gateway. The docker command/image, itself runs fine without any errors, but for some reason it isn't able to recognize the url exposed by ngrok. Any ideas what's wrong?

Dockerfile

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /app

COPY requirements.txt ./

COPY Main.py wsgi.py EmailSender.py AppConfig.py CompareCopyFgData.py SlackPayload.py Queries.py ./

RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt

ENV FLASK_APP=Main.py
ENV FLASK_ENV=production

ENTRYPOINT ["gunicorn", "--bind", "0.0.0.0:5000", "wsgi:flaskApp", "--workers", "4"]

docker-compose.yml

version: "3.9"
services:
  slackbot:
    build: 
      context: App/
      dockerfile: Dockerfile
    env_file:
      - ./App/.env

Steps to reproduce:

  1. Start ngrok in a terminal using ngrok http 5000
  2. Set up docker-compose.yml and Dockerfile with the appropriate files and run commands
  3. In a new terminal, point to the folder containing docker-compose.yml image and run command docker-compose up --build
  4. If no errors, go to slack and run a slash command and wait to see logs in Docker Terminal window

Expected result:

Docker to accept incoming slack commands and print logs, send modal(s) to slack and receive user inputs etc

Actual result:

Nothing happens in docker. The 4 workers are started and keep waiting/listening for a payload/data to come in, even though ngrok is running.

Screen Shot 2022-05-01 at 2 17 27 PM

Screen Shot 2022-05-01 at 2 17 45 PM

Proxy error

Hi there,

I received a proxy error like this:
Proxy error: Could not proxy request /api/login from frontend.demo.test to http://backend.demo.test/. frontend_1 | See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).

Help me, please. Thanks!

Where do I ask questions about specific setup's?

Hi @osteel. Let me first thank you for this Docker tutorial. I am using it for over a year now for my local development, but never got around to make an attempt to getting to know it. This tutorial series is an excellent starting point.

I have a specific setup I still don't know how to setup. I am also somewhat of a paranoia dinosaur and don't use social media. You either have no e-mail or prefer not to share the address with the public, understandably so. So my question is if you are available for advice in specific situations and if so, where do I ask my questions?

version error

following your first part of this tut iget this error, when adding mysql:

ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the services key, or omit the version key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

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.