Skip to content

Commit d513c7a

Browse files
committed
docker image & compose added with readme
0 parents  commit d513c7a

File tree

8 files changed

+1895
-0
lines changed

8 files changed

+1895
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
./Docker/*
2+
./docker-files/*
3+
4+
*Dockerfile

.env-example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
APP_ENV=local
2+
APP_PORT=8082
3+
APP_PORT_SSL=8043

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# PHP 7.4 & Apache Dockerfile Example
2+
3+
A base PHP 7.4 Apache 2 image[^docker_pull_cmd_note] for demonstrating legacy projects available at [EWC Docker Hub](https://hub.docker.com/r/ewc2020/web).
4+
5+
An old version of ***PHP*** that some codebase sites still require to emulate a ***production*** environment to run in.
6+
7+
Other Packages Included:
8+
9+
- Node
10+
- Composer
11+
- libxml2-dev
12+
- libzip-dev
13+
- libyaml-dev
14+
- zip
15+
- git
16+
- nodejs
17+
- default-mysql-client
18+
- vim
19+
- npm i npm@latest -g
20+
- yaml
21+
22+
PHP Extensions:
23+
24+
- gettext
25+
- mysqli
26+
- pdo_mysql
27+
- zip
28+
- yaml
29+
30+
31+
## Build Image
32+
33+
Build the ***Docker Image*** without using ***cached*** versions of previous image build stages.
34+
35+
**N.B.**
36+
37+
This ***requires*** that the file be named `Dockerfile` and nothing else.
38+
39+
```bash
40+
sudo docker build --target php-7-4-build --no-cache -t php-7-4-web-server .
41+
```
42+
43+
### Create A Container
44+
45+
This creates a named container and attaches it to the ***host network*** and may cause port conflict if the host machine is already listening on any exposed ports from the ***Docker Image*** being used.
46+
47+
```bash
48+
sudo docker run -d --network host --name container-name php-7-4-web-server
49+
```
50+
51+
**OR**
52+
53+
This creates a named container and attaches it to the ***bridge network*** and allows for ***port forward mapping*** from the ***host*** to the ***Container***. The ports are mapped **8080** on the ***Host*** machine to port **80** on the ***Container***
54+
55+
```bash
56+
sudo docker run -d --network bridge --expose 8080:80 --name container-name php-7-4-web-server
57+
```
58+
59+
### Start Container
60+
61+
```bash
62+
sudo docker start php-7-4-web-server
63+
```
64+
65+
### Stop Container
66+
67+
```bash
68+
sudo docker stop php-7-4-web-server
69+
```
70+
71+
## Docker Compose
72+
73+
A `docker-compose` configuration file is included to simplify the build & deployment of the image.
74+
75+
### Build - No Cache
76+
77+
This is only necessary when completely rebuilding the image to make sure all parts are rebuilt[^compose_name_note].
78+
79+
```bash
80+
sudo docker-compose build --no-cache php-7-4-web-server
81+
```
82+
83+
### Build & Up
84+
85+
This will try to use a local version or rebuild the image with current context.
86+
87+
```bash
88+
sudo docker-compose up --build -d
89+
```
90+
91+
## Connect To Container
92+
93+
```bash
94+
sudo docker exec -it php-7-4-web-server /bin/bash
95+
```
96+
97+
[^docker_pull_cmd_note]: Use `docker pull ewc2020/web:php-5.6-apache` to get a copy of the image.
98+
99+
[^compose_name_note]: The `php-7-4-web-server` container name to build the image for.

docker-compose.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: '3.7'
2+
3+
services:
4+
php-7-4-web-server:
5+
container_name: php-7-4-web-server
6+
tty: true
7+
restart: unless-stopped
8+
build:
9+
context: .
10+
target: php-7-4-build
11+
dockerfile: php-7-4-apache.Dockerfile
12+
args:
13+
- APP_ENV=${APP_ENV}
14+
labels:
15+
ewc.name: "Web Server"
16+
ewc.description: "PHP & Apache Web Server"
17+
ewc.php.version: "7.4"
18+
ewc.label-with-empty-value: ""
19+
image: ewc2020/web:php-7-4-apache
20+
environment:
21+
- APP_ENV=${APP_ENV}
22+
- APP_PORT=${APP_PORT}
23+
- APP_PORT_SSL=${APP_PORT_SSL}
24+
working_dir: /var/www
25+
ports:
26+
- ${APP_PORT}:80
27+
- ${APP_PORT_SSL}:443
28+
volumes:
29+
- ./public_html:/var/www/html
30+
- ./docker-files/php/local.ini:/usr/local/etc/php.ini
31+
networks:
32+
- webapp_network
33+
34+
networks:
35+
webapp_network:
36+

0 commit comments

Comments
 (0)