Skip to content

Commit 3c61b7e

Browse files
committed
Initial commit.
0 parents  commit 3c61b7e

File tree

3 files changed

+188
-0
lines changed

3 files changed

+188
-0
lines changed

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# PHP Apache Container (Built with Ansible)
2+
3+
[![Build Status](https://travis-ci.org/geerlingguy/php-apache-container.svg?branch=master)](https://travis-ci.org/geerlingguy/php-apache-container) [![](https://images.microbadger.com/badges/image/geerlingguy/php-apache.svg)](https://microbadger.com/images/geerlingguy/php-apache "Get your own image badge on microbadger.com")
4+
5+
This project is in it's early stages. _There will be bugs!_ You may be better served using the [official PHP Docker image](https://hub.docker.com/_/php/) if it meets your requirements.
6+
7+
This project is composed of three main parts:
8+
9+
- **Ansible project**: This project is maintained on GitHub: [geerlingguy/php-apache-container](https://github.com/geerlingguy/php-apache-container). Please file issues, support requests, etc. against this GitHub repository.
10+
- **Docker Hub Image**: If you just want to use [the `geerlingguy/php-apache` Docker image](https://hub.docker.com/r/geerlingguy/php-apache/) in your project, you can pull it from Docker Hub.
11+
- **Ansible Role**: If you need a flexible Ansible role that's compatible with both traditional servers and containerized builds, check out [`geerlingguy.php`](https://galaxy.ansible.com/geerlingguy/php/) on Ansible Galaxy. (This is the Ansible role that does the bulk of the work in managing the PHP container.)
12+
13+
## Versions
14+
15+
Currently maintained versions include:
16+
17+
- `7.2`, `7.2.x`, `latest`: PHP 7.2.x
18+
- `7.1`, `7.1.x`: PHP 7.1.x
19+
- `7.0`, `7.0.x`: PHP 7.0.x
20+
- `5.6`, `5.6.x`: PHP 5.6.x
21+
22+
## Standalone Usage
23+
24+
If you want to use the `geerlingguy/php-apache` image from Docker Hub, you don't need to install or use this project at all. You can quickly build a PHP container locally with:
25+
26+
docker run -d --name=php -p 80:80 geerlingguy/php-apache:latest /usr/sbin/apache2ctl -D FOREGROUND
27+
28+
You can also wrap up that configuration in a `Dockerfile` and/or a `docker-compose.yml` file if you want to keep things simple. For example:
29+
30+
```
31+
version: "3"
32+
33+
services:
34+
php:
35+
image: geerlingguy/php-apache:latest
36+
container_name: php-apache
37+
ports:
38+
- "80:80"
39+
restart: always
40+
# See 'Custom PHP codebase' for instructions for volumes.
41+
volumes: []
42+
command: ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
43+
44+
Then run:
45+
46+
docker-compose up -d
47+
48+
Now you should be able to access the default home page at `http://localhost/`.
49+
50+
### Custom PHP codebase
51+
52+
If you have a codebase inside the folder `web`, mount it as a volume like `-v ./web:/var/www/html:rw,delegated`.
53+
54+
Or, if using a Docker Compose file:
55+
56+
services:
57+
myapp:
58+
...
59+
volumes:
60+
- ./web:/var/www/html:rw,delegated
61+
62+
If you wish to build an image using this image as the base (e.g. for deploying to production), create a Dockerfile and `COPY` the webroot into place so it's part of the image.
63+
64+
## Management with Ansible
65+
66+
### Prerequisites
67+
68+
Before using this project to build and maintain PHP images for Docker, you need to have the following installed:
69+
70+
- [Docker Community Edition](https://docs.docker.com/engine/installation/) (for Mac, Windows, or Linux)
71+
- [Ansible](http://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)
72+
73+
### Build the image
74+
75+
ansible-playbook main.yml
76+
77+
Once the image is built, you can run `docker images` to see the `TODO` image that was generated.
78+
79+
### Push the image to Docker Hub
80+
81+
Currently, the process for updating this image on Docker Hub is manual. Eventually this will be automated via Travis CI.
82+
83+
1. Log into Docker Hub on the command line:
84+
85+
docker login --username=geerlingguy
86+
87+
1. Tag the latest version (only if this is the latest/default version):
88+
89+
docker tag [image id] geerlingguy/php-apache:latest
90+
91+
1. Tag the Solr major version:
92+
93+
docker tag [image id] geerlingguy/php-apache:7.2 # or 7.1, etc.
94+
docker tag [image id] geerlingguy/php-apache:7.2.5 # the specific version
95+
96+
1. Push tags to Docker Hub:
97+
98+
docker push geerlingguy/php-apache:latest # (if this was just tagged)
99+
docker push geerlingguy/php-apache:7.2 # or 7.1, etc.
100+
docker push geerlingguy/php-apache:7.2.5 # the specific version
101+
102+
## License
103+
104+
MIT / BSD
105+
106+
## Author Information
107+
108+
This container build was created in 2018 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).

main.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
- hosts: localhost
3+
connection: local
4+
gather_facts: no
5+
6+
vars:
7+
base_image: debian:stretch
8+
container_name: build_container
9+
image_name: php
10+
11+
php_version: '7.2'
12+
php_packages_extra:
13+
- libapache2-mod-php
14+
php_install_recommends: no
15+
16+
pre_tasks:
17+
- name: Make the base image available locally.
18+
docker_image:
19+
name: '{{ base_image }}'
20+
21+
- name: Create the Docker container.
22+
docker_container:
23+
image: '{{ base_image }}'
24+
name: '{{ container_name }}'
25+
command: sleep infinity
26+
27+
- name: Add the newly created container to the inventory.
28+
add_host:
29+
hostname: '{{ container_name }}'
30+
ansible_connection: docker
31+
32+
- name: Ensure Python is installed.
33+
raw: >
34+
apt-get update &&
35+
apt-get install -y --no-install-recommends python
36+
delegate_to: '{{ container_name }}'
37+
38+
- name: Gather facts inside the container.
39+
setup:
40+
delegate_to: '{{ container_name }}'
41+
42+
roles:
43+
- name: geerlingguy.apache
44+
delegate_to: '{{ container_name }}'
45+
46+
- name: geerlingguy.php-versions
47+
delegate_to: '{{ container_name }}'
48+
49+
- name: geerlingguy.php
50+
delegate_to: '{{ container_name }}'
51+
52+
- name: geerlingguy.php-mysql
53+
delegate_to: '{{ container_name }}'
54+
55+
- name: geerlingguy.composer
56+
delegate_to: '{{ container_name }}'
57+
58+
post_tasks:
59+
- name: Clean up the container.
60+
shell: >
61+
apt-get remove --purge -y python
62+
rm -rf /var/lib/apt/lists/*
63+
delegate_to: '{{ container_name }}'
64+
65+
- name: Commit the container.
66+
command: >
67+
docker commit
68+
-c 'CMD ["nginx", "-g", "daemon off;"]'
69+
{{ container_name }} {{ image_name }}
70+
71+
- name: Remove the container.
72+
docker_container:
73+
name: '{{ container_name }}'
74+
state: absent

requirements.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- src: geerlingguy.apache
3+
- src: geerlingguy.php-versions
4+
- src: geerlingguy.php
5+
- src: geerlingguy.php-mysql
6+
- src: geerlingguy.composer

0 commit comments

Comments
 (0)