GithubHelp home page GithubHelp logo

treygrr / docker-lepp Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 2.53 MB

This is a docker based lepp stack for application development. This includes postgres, pgadmin, php 7.4, nginx, composer, and laravel.

Shell 4.74% Dockerfile 0.51% JavaScript 94.76%
docker postgres docker-container nginx laravel composer pgadmin dockerfile docker-compose

docker-lepp's Introduction

How to use this docker project

Quick Notes:

Most configuration can be modified in the .env file of this projects root directory. I tried following a naming convention if it was a docker environment variable that follows as such:

DOCKER_APPLICATIONNAME_VARIABLENAME=

Docker compose

docker-compose up

  • This command will run the containers according to how they configured in the docker-compose.yml file in the root of the project folder.

docker-compose up -d

  • This command will do the same as the above but will detach the docker process from the active terminal window.

docker-compose ps

  • This command will list all the currently running containers

docker-compose down

  • This command will take down the currently running containers

docker-compose rmi

If you need to update the container images:

docker-compose stop
docker-compose rm -f
docker-compose pull   
docker-compose up -d

Docker build

docker build .

  • This command will build the dockerfile in your current working directory.

docker build -t username/reponame:latest .

  • This command builds your dockerfile in your cwd and tags it because of the '-t' flag.

    • username - is your docker community username: in my case treydwg

    • reponame - is the repo that this image belongs to: ex. nginx

    • :latest - is the tag or version: ex. stable, latest, 1.2, alpine, etc.

    • docker build -t treydwg/nginx:latest for example

docker images

  • This command will list out all the currently built images

docker tag oldname newname

  • Follow the same naming convention as build, this command will rename the image. In doing this the image is cloned with the new name and the old image still remains.

docker rmi oldname

  • This command can be used to clean up the old container from the previous command.

Getting Started with a new Application

  1. Copy .example.env and rename it to .env (If you are in windows you must do this in powershell or in vscode because windows doesn't like files that start with symbols)
    • 1.a Change DOCKER_CONTAINER_PREFIX to a shortname of your app. This will stop docker containers from interacting with each other and ensure that they all have their own instance.
    • 1.b If you plan on running multiple projects at one time you should shift each port to a new unused port number. For ex: in docker-compose.yml change
  2. Change DOCKER_NGINX_HOST=testsite.test to what ever url you would like for example DOCKER_NGINX_HOST=dieselapi.net
    • 2.a If you are on a windows machine add the domain you assigned to the env variable DOCKER_NGINX_HOST to your windows hosts file. This is usually located at C:\Windows\System32\drivers\etc
      • ex: 127.0.0.1 dieselapi.net
    • 2.b Add this as well for local development purposes:
      • ex: 127.0.0.1 ${DOCKER_CONTAINER_PREFIX}-postgres would be 127.0.0.1 testsite-postgres or what ever you set the prefix to.
  3. If you choose to modify your postgres db credentials you can modify them in the .env file under the DOCKER_POSTGRES_* environment variables.
  4. By default Nginx will look for your project file according to the root declaration in the Nginx site configuration file located in ./nginx/siteconfig.conf file.
    • If you are building a laravel application be sure to change the path of the root inside the nginx site configuration file to the path of your laravel project.
    • 4.a Open the file from the project root directory with /nginx/siteconfigServer.conf. From here look towards line 32 for fastcgi_pass vin-php:9000; vin-php:9000; needs to match your docker container name for PHP and it's port that was set eariler. So in this instance it looks like above.
  5. Run the command docker compose up -d
  6. If you run into a server 500 error when trying to reach your API.
  • 6.a SSH into the nginx container via docker exec -it {projectprefix}-nginx /bin/bash
  • 6.b Navigate to the project directory via cd app
  • 6.c Run composer install
  • 6.d Run php artisan key:generate

Database

By default the database in configured to port forward local connections to the containers internal network based on the standard postgres port of 5432. This can be changed inside of the .env file at DOCKER_POSTGRES_LOCAL_PORT if you desire a different functioning local machine port.

Overview of database management

In this docker project there is a visual database management software bundled into the compose file called pgAdmin. Once you are up and running, you can connect to the docker container that is holding our postgres database via it's container name. For ex: vin-postgres or {prefix}-postgres

The username will be what you set it as in the .env variable in the root of this project. This will be the same scenario for your Port, Database name, and Password.

You can export and import backup files from this UI as well as create tables if you prefer a GUI.

If you prefer doing so from the command line see below!

SSH to docker container

docker exec -it [container-name] /bin/bash Executing this above command will put you into a bash shell for the specified container.

docker exec -it vin-nginx /bin/bash

To exit bash shell or leave containers command line simply type exit on a new line and hit return.

Dropping a database from docker

SSH into the docker container for postgres like above. An example will be:

docker exec -it vin-postgres /bin/bash

Once you are in the container to drop your database you should know the db name Example stripped:

PGPASSWORD="yourpasswordhere" pg_dump -U postgresusernamehere yourdatabasenametodump > /path/toyour/file.sql

A functioning example for this project is:

PGPASSWORD="password" pg_dump -U postgres testdb > /backups/backupfile.sql

Restoring from a dumped file

Again SSH into the postgres container. From here you should then run the following command:

PGPASSWORD="password" psql -U postgres testdb < /backups/backupfile.sql

How do I get the backupfile from and into the container?

In order for your backup to save properly to your machine. Make sure that you are pg_dumping to the /backups root directory on the virtual machine. This docker project has a system link that will allow anything in the /backups folder in the virtual machine to save to your local machine to the postgres-data-dump directory in the root of this project. In addition to the above functionality it goes in reverse as well. You can drag and drop a database dump file to postgres-data-dump and it will be available in the /backups folder in the virtual machine for you to run a psql restore (see Restoring from a dumped file).

docker-lepp's People

Contributors

treygrr avatar

Watchers

James Cloos avatar  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.