Skip to content

Commit

Permalink
Merge pull request #5 from nspalo/webstack/v1.0.0
Browse files Browse the repository at this point in the history
Webstack/v1.0.0
  • Loading branch information
nspalo authored Aug 23, 2021
2 parents e4f0310 + 325e9fe commit 57da4bf
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Environment
/.idea
/.idea

# MySQL
/docker/containers/mysql/
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# Docker Study
> This is a simple repo to learn the basics in setting up a
> *Web development environment with __Docker__*.
> This is a simple repo to learn the basics in setting up a
> *Web development environment with NginX, MySQL, and PHP inside a __Docker__ container*.
## Web Stack
- Docker Containers
- nginx
- mysql
- php
- NginX
- nginx:stable-alpine
- MySQL 5.7
- mysql:5.7.22
- PHP 7
- php:7.2-fpm-alpine

## Table of Contents
| Branch Name | What's Inside |
| ------------- | ------------- |
| [webstack/v1.0.0](https://github.com/nspalo/docker-study/tree/webstack/v1.0.0) | nginx:stable-alpine, mysql:5.7.22, php:7.2-fpm-alpine |
| [webstack/v2.0.0](https://github.com/nspalo/docker-study/tree/webstack/v2.0.0) | nginx:stable-alpine, mysql:5.7.22, php:7.4-fpm-alpine |
| [webstack/v2.0.0](https://github.com/nspalo/docker-study/tree/webstack/v2.0.0) | nginx:stable-alpine, mysql:5.7.22, php:7.4-fpm-alpine |
62 changes: 62 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,65 @@
>
## Docker Directory
- This directory will host the docker related files.

## Docker Commands
> Notes of some simple docker commands for building, starting, and stopping the service containers
> ### Note:
> In this structure, we always need to add a -f flag and the path to the docker compose yaml file
> which in out case is -f ./docker/docker-compose/docker-compose.yml
### Building the service containers
```
// Build the services/containers
docker-compose -f ./docker/docker-compose/docker-compose.yml build
```

### Starting the service
```
docker-compose -f ./docker/docker-compose/docker-compose.yml up
// add the -d (detach) option to run in the background
docker-compose -f ./docker/docker-compose/docker-compose.yml up -d
// use the container name for a specific service
// docker-compose up <_ContainerName_>
docker-compose -f ./docker/docker-compose/docker-compose.yml up php
```

### Stopping the service
```
docker-compose -f ./docker/docker-compose/docker-compose.yml down -v
// -v, --volumes Remove named volumes declared in the `volumes`
// section of the Compose file and anonymous volumes
// attached to containers.
// to stop a specific service, use the stop command followed by th container name
// docker-compose stop <_ContainerName_>
docker-compose -f ./docker/docker-compose/docker-compose.yml stop mysql
```

### Restarting the service
```
docker-compose -f ./docker/docker-compose/docker-compose.yml restart
// use the container name for a specific service
docker-compose -f ./docker/docker-compose/docker-compose.yml restart php
```

### Running arbitrary commands inside a service container
```
// Use docker-compose exec to run command inside the container.
// - e.g.: To run php artisan migrate commad
// - format: docker-compose exec <_ContainerName_> php <_PathToArtisan_> migrate
docker-compose -f ./docker/docker-compose/docker-compose.yml exec php php /var/www/html/artisan migrate
```

```
// building & starting (detach)
docker-compose -f ./docker/docker-compose/docker-compose.yml up -d --build
// Check if index.php exists
docker-compose -f ./docker/docker-compose/docker-compose.yml exec nginx ls /var/www/html/public
```
5 changes: 5 additions & 0 deletions docker/containers/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Install PHP 7.2
FROM php:7.2-fpm-alpine

# Install PHP Extension
RUN docker-php-ext-install pdo pdo_mysql
22 changes: 22 additions & 0 deletions docker/containers/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server {
listen 80;
index index.php index.html;
# server_name <ServerName>;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public/;

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}

location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
54 changes: 54 additions & 0 deletions docker/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: '3'

networks:
web-app:

services:
# Container: NginX
nginx:
networks:
- web-app
container_name: nginx
image: library/nginx:stable-alpine
ports:
- "9100:80"
volumes:
- ../../src:/var/www/html
- ../../docker/containers/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql

# Container: MySQL
mysql:
networks:
- web-app
container_name: mysql
image: library/mysql:5.7.22
restart: unless-stopped
tty: true
ports:
- "3306:3306"
volumes:
- ../../docker/containers/mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: db_docker_study
MYSQL_USER: dbUserDev
MYSQL_PASSWORD: dbUserDev123
MYSQL_ROOT_PASSWORD: dbUserRoot123
SERVICE_TAGS: dev
SERVICE_NAME: mysql

# Container: PHP
php:
networks:
- web-app
container_name: php
build:
context: ./
dockerfile: ../../docker/containers/Dockerfile
image: php:php7.2-fpm-alpine
ports:
- "9000:9000"
volumes:
- ../../src:/var/www/html
11 changes: 11 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@
## Web App/Project Directory
- This directory will host the Web App/Project related files.

### Test Run
```
// Build and Start Services and Containers
// - see: ./docker/README file for more
docker-compose -f ./docker/docker-compose/docker-compose.yml build
docker-compose -f ./docker/docker-compose/docker-compose.yml up -d
// Access Web
http://localhost:9100/
```
10 changes: 10 additions & 0 deletions src/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test - NginX</title>
</head>
<body>
<h1>It Works!!!</h1>
</body>
</html>

0 comments on commit 57da4bf

Please sign in to comment.