|
| 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. |
0 commit comments