Skip to content

Commit 5dde756

Browse files
authored
Merge pull request #13 from mattrayner/develop
v0.2.1
2 parents 7f2addd + 8d5929a commit 5dde756

File tree

10 files changed

+220
-101
lines changed

10 files changed

+220
-101
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.gitignore
22
CHANGELOG.md
33
circle.yml
4+
docker-compose.test.yml
45
docs/
56
tests/
67
LICENSE

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
.idea
2-
tests/actual

README.md

Lines changed: 159 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# ![Docker-LAMP][logo]
2-
Docker-LAMP is a docker image that includes the phusion base image, [Apache][apache], [MySQL][mysql] and [PHP][php] all in one handy package.
2+
Docker-LAMP is a set of docker images that include the phusion baseimage (both 14.04 and 16.04 varieties), along with a LAMP stack ([Apache][apache], [MySQL][mysql] and [PHP][php]) all in one handy package.
3+
4+
With both Ubuntu **16.04** and **14.04** images on the latest-1604 and latest-1404 tags, Docker-LAMP is flexible enough to use with all of your LAMP projects.
35

46
[![Build Status][shield-build-status]][info-build-status]
5-
[![Dokcer Status][shield-quay]][info-quay]
7+
[![Docker Hub][shield-docker-hub]][info-docker-hub]
8+
[![Quay Status][shield-quay]][info-quay]
69
[![License][shield-license]][info-license]
710

811

@@ -11,144 +14,247 @@ Docker-LAMP is a docker image that includes the phusion base image, [Apache][apa
1114
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1215

1316

17+
- [Introduction](#introduction)
1418
- [Component Versions](#component-versions)
1519
- [Using the image](#using-the-image)
16-
- [Building from source](#building-from-source)
17-
- [Using with a Dockerfile](#using-with-a-dockerfile)
18-
- [MySQL](#mysql)
20+
- [On the command line](#on-the-command-line)
21+
- [With a Dockerfile](#with-a-dockerfile)
22+
- [MySQL Databases](#mysql-databases)
1923
- [Creating a database](#creating-a-database)
2024
- [PHPMyAdmin](#phpmyadmin)
2125
- [Command Line](#command-line)
2226
- [Adding your own content](#adding-your-own-content)
23-
- [Adding your own 'php'](#adding-your-own-php)
27+
- [Adding your app](#adding-your-app)
2428
- [Persisting your MySQL](#persisting-your-mysql)
25-
- [Doing both (recommended)](#doing-both-recommended)
29+
- [Doing both](#doing-both)
2630
- [`.bash_profile` alias examples](#bash_profile-alias-examples)
27-
- [Credits](#credits)
31+
- [Example usage](#example-usage)
32+
- [Developing the image](#developing-the-image)
33+
- [Building and running](#building-and-running)
34+
- [Testing](#testing)
35+
- [One-line testing command](#one-line-testing-command)
36+
- [`docker-compose -f docker-compose.test.yml -p ci build;`](#docker-compose--f-docker-composetestyml--p-ci-build)
37+
- [`docker-compose -f docker-compose.test.yml -p ci up -d;`](#docker-compose--f-docker-composetestyml--p-ci-up--d)
38+
- [`docker logs -f ci_sut_1;`](#docker-logs--f-ci_sut_1)
39+
- [`echo "Exited with status code: $(docker wait ci_sut_1)"`](#echo-exited-with-status-code-docker-wait-ci_sut_1)
40+
- [Inspiration](#inspiration)
41+
- [Contributing](#contributing)
42+
- [License](#license)
2843

2944
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3045

46+
## Introduction
47+
As a developer, part of my day to day role is to build LAMP applications. I searched in vein for an image that had everything I wanted, up-to-date packages, a simple interface, good documentation and active support.
48+
49+
To complicate things even further I needed an image, or actually two, that would run my applications on both 14.04 and 16.04. Having two entirely separate workflows didn't make any sense to me, and Docker-LAMP was born.
50+
51+
Designed to be a single interface that just 'gets out of your way', and works on both 14.04 and 16.04, you can move between both bases without changing how you work with Docker.
3152

3253
## Component Versions
33-
Component | Version
34-
---|---
35-
[Apache][apache] | `2.4.7`
36-
[MySQL][mysql] | `5.5.50-0ubuntu0.14.04.1`
37-
[PHP][php] | `5.5.9-1ubuntu4.19`
54+
Component | 14.04 Version | 16.04 Version
55+
---|---|---
56+
[Apache][apache] | `2.4.7` | `2.4.18`
57+
[MySQL][mysql] | `5.5.50-0ubuntu0.14.04.1` | `5.7.13-0ubuntu0.16.04.2`
58+
[PHP][php] | `5.5.9-1ubuntu4.19` | `5.6.25-1+deb.sury.org~xenial+1`
59+
[phpMyAdmin][phpmyadmin] | `4.6.4` | `4.6.4`
3860

3961

4062
## Using the image
41-
### Building from source
42-
```
43-
docker build -t=mattrayner/lamp .
44-
docker run -d -p 80:80 -p 3306:3306 mattrayner/lamp
63+
### On the command line
64+
This is the quickest way
65+
```bash
66+
# Launch a 16.04 based image
67+
docker run -p "80:80" -v ${PWD}/app:/app mattrayner/lamp:latest-1604
68+
69+
# Launch a 14.04 based image
70+
docker run -p "80:80" -v ${PWD}/app:/app mattrayner/lamp:latest-1404
4571
```
4672

47-
### Using with a Dockerfile
48-
```
49-
FROM mattrayner/lamp:latest
73+
### With a Dockerfile
74+
```docker
75+
FROM mattrayner/lamp:latest-1604
5076
5177
# Your custom commands
5278
5379
CMD ["/run.sh"]
5480
```
5581

56-
### MySQL
57-
The default image comes with a `root` MySQL account that has no password. This account is only available locally though i.e. within your application. It is not availzble from outside your docker image.
82+
### MySQL Databases
83+
By default, the image comes with a `root` MySQL account that has no password. This account is only available locally, i.e. within your application. It is not available from outside your docker image or through phpMyAdmin.
5884

59-
When you first run the image you'll see a message showing your `admin` user password. This user can be used locally and externally. Either by connecting to port 3306 using a tool like MySQL Workbench or Sequel Pro. If you need this login later, you can run `docker logs CONTAINER_ID` and you should see it at the top of the log.
85+
When you first run the image you'll see a message showing your `admin` user's password. This user can be used locally and externally, either by connecting to your MySQL port (default 3306) and using a tool like MySQL Workbench or Sequel Pro, or through phpMyAdmin.
6086

61-
The image comes pre-installed with PHPMyAdmin available from `/phpmyadmin`. **NOTE:** you cannot use the `root` user with PHPMyAdmin.
87+
If you need this login later, you can run `docker logs CONTAINER_ID` and you should see it at the top of the log.
6288

6389
#### Creating a database
6490
So your application needs a database - you have two options...
91+
6592
1. PHPMyAdmin
6693
2. Command line
6794

6895
##### PHPMyAdmin
69-
Simply log in with the details mentioned above and create a database
96+
Docker-LAMP comes pre-installed with phpMyAdmin available from `http://DOCKER_ADDRESS/phpmyadmin`.
97+
98+
**NOTE:** you cannot use the `root` user with PHPMyAdmin. We recommend logging in with the admin user mentioned in the introduction to this section.
7099

71100
##### Command Line
72101
First, get the ID of your running container with `docker ps`, then run the below command replacing `CONTAINER_ID` and `DATABASE_NAME` with your required values:
73-
74-
```
102+
```bash
75103
docker exec CONTAINER_ID mysql -uroot -e "create database DATABASE_NAME"
76104
```
77105

78106

79107
## Adding your own content
80-
The 'easiest' way to add your own content to the lamp image is using Docker volumes. This will effectively 'sync' a particular folder on your machine with that on the docker machine.
108+
The 'easiest' way to add your own content to the lamp image is using Docker volumes. This will effectively 'sync' a particular folder on your machine with that on the docker container.
81109

82110
The below examples assume the following project layout and that you are running the commands from the 'project root'.
83-
84111
```
85112
/ (project root)
86113
/app/ (your PHP files live here)
114+
/mysql/ (docker will create this and store your MySQL data here)
87115
```
88116

89-
That is to say that your project contains a folder called `app` containing all of your app's code.
117+
In english, your project should contain a folder called `app` containing all of your app's code. That's pretty much it.
90118

91-
### Adding your own 'php'
92-
```
119+
### Adding your app
120+
The below command will run the docker image `mattrayner/lamp` interactively, exposing port `80` on the host machine with port `80` on the docker container. It will then create a volume linking the `app/` directory within your project to the `/app` directory on the container. This is where Apache is expecting your PHP to live.
121+
```bash
93122
docker run -i -t -p "80:80" -v ${PWD}/app:/app mattrayner/lamp
94123
```
95124

96-
The above will run the docker image `mattrayner/lamp` interactively, exposeing port `80` on the host machine with port `80` on the docker container. It will then create a volume linking `app/` within the project directory to `/app` on the containers file directory. This will load your PHP into apache.
97-
98125
### Persisting your MySQL
99-
```
126+
The below command will run the docker image `mattrayner/lamp`, creating a `mysql/` folder within your project. This folder will be linked to `/var/lib/mysql` where all of the MySQL files from container lives. You will now be able to stop/start the container and keep your database changes.
127+
128+
You may also add `-p 3306:3306` after `-p 80:80` to expose the mysql sockets on your host machine. This will allow you to connect an external application such as SequelPro or MySQL Workbench.
129+
```bash
100130
docker run -i -t -p "80:80" -v ${PWD}/mysql:/var/lib/mysql mattrayner/lamp
101131
```
102132

103-
The above will run the docker image, creating a `mysql/` folder within our project. This folder will contain all of the MySQL files from the docker container. Therefore you will be able to stop/start the container and keep your databases.
104-
105-
You may also add `-p 3306:3306` after `-p 80:80` to expose the mysql sockets on your host machine.
106-
107-
### Doing both (recommended)
108-
```
109-
docker run -i -t -p "80:80" -p "3306:3306" -v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql mattrayner/lamp:latest
133+
### Doing both
134+
The below command is our 'recommended' solution. It both adds your own PHP and persists database files. We have created a more advanced alias in our `.bash_profile` files to enable the short commands `ldi` and `launchdocker`. See the next section for an example.
135+
```bash
136+
docker run -i -t -p "80:80" -v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql mattrayner/lamp:latest
110137
```
111138

112-
The above is our 'recommended' solution. It both adds your own PHP and persists database files. We have created an alias in our `.bash_profile` files to enable the short command `ld` or `launch-docker`.
113-
114139
#### `.bash_profile` alias examples
115-
```
116-
# Create a helper function to launch docker with overrideable parameters
140+
The below example can be added to your `~/.bash_profile` file to add the alias commands `ldi` and `launchdocker`. By default it will launch the 16.04 image - if you need the 14.04 image, simply change the `docker run` command to use `mattrayner/lamp:latest-1404` instead of `mattrayner/lamp:latest`.
141+
```bash
142+
# A helper function to launch docker container using mattrayner/lamp with overrideable parameters
143+
#
144+
# $1 - Apache Port (optional)
145+
# $2 - MySQL Port (optional - no value will cause MySQL not to be mapped)
117146
function launchdockerwithparams {
118147
APACHE_PORT=80
119-
MYSQL_PORT=3306
148+
MYSQL_PORT_COMMAND=""
120149

121150
if ! [[ -z "$1" ]]; then
122151
APACHE_PORT=$1
123152
fi
124153

125154
if ! [[ -z "$2" ]]; then
126-
MYSQL_PORT=$2
155+
MYSQL_PORT_COMMAND="-p \"$2:3306\""
127156
fi
128157

129-
docker run -i -t -p "$APACHE_PORT:80" -p "$MYSQL_PORT:3306" -v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql mattrayner/lamp:latest
158+
docker run -i -t -p "$APACHE_PORT:80" $MYSQL_PORT_COMMAND -v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql mattrayner/lamp:latest
130159
}
131160
alias launchdocker='launchdockerwithparams $1 $2'
132-
alias ld='launchdockerwithparams $1 $2'
161+
alias ldi='launchdockerwithparams $1 $2'
162+
```
163+
164+
##### Example usage
165+
```bash
166+
# Launch docker and map port 80 for apache
167+
ldi
168+
169+
# Launch docker and map port 8080 for apache
170+
ldi 8080
171+
172+
# Launch docker and map port 3000 for apache along with 3306 for MySQL
173+
ldi 3000 3306
174+
```
175+
176+
177+
## Developing the image
178+
### Building and running
179+
```bash
180+
# Clone the project from Github
181+
git clone https://github.com/mattrayner/docker-lamp.git
182+
cd docker-lamp
183+
184+
# Build both the 16.04 image and the 14.04 iamge
185+
docker build -t=mattrayner/lamp:latest -f Dockerfile .
186+
docker build -t=mattrayner/lamp:latest-1404 -f Dockerfile1404 .
187+
188+
# Run the 14.04 image as a container
189+
docker run -p "3000:80" mattrayner/lamp:latest-1404 -d
190+
191+
# Sleep to allow the container to boot
192+
sleep 5
193+
194+
# Curl out the contents of our new container
195+
curl "http://$(docker-machine ip):3000/"
196+
```
197+
198+
### Testing
199+
We use `docker-compose` to setup, build and run our testing environment. It allows us to offload a large amount of the testing overhead to Docker, and to ensure that we always test our image in a consistent way thats not affected by the host machine.
200+
201+
### One-line testing command
202+
We've developed a single-line test command you can run on your machine within the `docker-lamp` directory. This will test any changes that may have been made, as well as comparing installed versions of Apache, MySQL, PHP and phpMyAdmin against those expected.
203+
```bash
204+
docker-compose -f docker-compose.test.yml -p ci build; docker-compose -f docker-compose.test.yml -p ci up -d; docker logs -f ci_sut_1; echo "Exited with status code: $(docker wait ci_sut_1)";
133205
```
134206

207+
So what does this command do?
208+
209+
#### `docker-compose -f docker-compose.test.yml -p ci build;`
210+
First, build that latest version of our docker-compose images.
211+
212+
#### `docker-compose -f docker-compose.test.yml -p ci up -d;`
213+
Launch our docker containers (`web1604`, `web1404` and `sut` or *system under tests*) in daemon mode.
214+
215+
#### `docker logs -f ci_sut_1;`
216+
Display all of the logging output from the `sut` container (extremely useful for debugging)
217+
218+
#### `echo "Exited with status code: $(docker wait ci_sut_1)"`
219+
Report back the status code that the `sut` container ended with.
220+
221+
222+
## Inspiration
223+
This image was originally based on [dgraziotin/lamp][dgraziotin-lamp], with a few changes to make it compatible with the Concrete5 CMS.
224+
225+
I also changed the setup to create ubuntu (well, baseimage, but you get what I'm saying) 14.04 and 16.04 images so that this project could be as useful as possible to as many people as possible.
226+
227+
228+
## Contributing
229+
If you wish to submit a bug fix or feature, you can create a pull request and it will be merged pending a code review.
230+
231+
1. Clone/fork it
232+
2. Create your feature branch (git checkout -b my-new-feature)
233+
3. Commit your changes (git commit -am 'Add some feature')
234+
4. Test your changes using the steps in [Testing](#testing)
235+
5. Push to the branch (git push origin my-new-feature)
236+
6. Create a new Pull Request
237+
135238

136-
## Credits
137-
This image is based on [dgraziotin/lamp][dgraziotin-lamp] with a few changes to make it compatible with Concrete5.
239+
## License
240+
Docker-LAMP is licensed under the [Apache 2.0 License][info-license].
138241

139242

140243
[logo]: https://cdn.rawgit.com/mattrayner/docker-lamp/831976c022782e592b7e2758464b2a9efe3da042/docs/logo.svg
141244

142245
[apache]: http://www.apache.org/
143246
[mysql]: https://www.mysql.com/
144247
[php]: http://php.net/
248+
[phpmyadmin]: https://www.phpmyadmin.net/
145249

146250
[info-build-status]: https://circleci.com/gh/mattrayner/docker-lamp
251+
[info-docker-hub]: https://hub.docker.com/r/mattrayner/lamp
147252
[info-quay]: https://quay.io/repository/mattrayner/docker-lamp
148253
[info-license]: LICENSE
149254

150255
[shield-build-status]: https://img.shields.io/circleci/project/mattrayner/docker-lamp.svg
256+
[shield-docker-hub]: https://img.shields.io/badge/docker%20hub-mattrayner%2Flamp-brightgreen.svg
151257
[shield-quay]: https://quay.io/repository/mattrayner/docker-lamp/status
152-
[shield-license]: https://img.shields.io/badge/license-MIT-blue.svg
258+
[shield-license]: https://img.shields.io/badge/license-Apache%202.0-blue.svg
153259

154260
[dgraziotin-lamp]: https://github.com/dgraziotin/osx-docker-lamp

circle.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,31 @@ machine:
55
dependencies:
66
override:
77
- docker info
8-
- docker build --no-cache -t=mattrayner/lamp:latest-1604 -f Dockerfile .
9-
- docker tag mattrayner/lamp:latest-1604 mattrayner/lamp:dev-1604
10-
- docker tag mattrayner/lamp:latest-1604 mattrayner/lamp:latest
11-
- docker tag mattrayner/lamp:latest-1604 mattrayner/lamp:dev
12-
- docker build --no-cache -t=mattrayner/lamp:latest-1404 -f Dockerfile1404 .
13-
- docker tag mattrayner/lamp:latest-1404 mattrayner/lamp:dev-1404
8+
- docker-compose -f docker-compose.test.yml -p ci build
9+
- docker-compose -f docker-compose.test.yml -p ci up -d
1410

1511
test:
1612
override:
17-
- pushd tests && . test.sh && popd
13+
- 'docker logs -f ci_sut_1; echo "Exited with status code: $(docker wait ci_sut_1)"; exit $(docker wait ci_sut_1)'
1814

1915
deployment:
2016
latest:
2117
branch: master
2218
commands:
2319
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
20+
- docker tag ci_web1604:latest mattrayner/lamp:latest
21+
- docker tag ci_web1604:latest mattrayner/lamp:latest-1604
22+
- docker tag ci_web1404:latest mattrayner/lamp:latest-1404
23+
- docker push mattrayner/lamp:latest
2424
- docker push mattrayner/lamp:latest-1604
2525
- docker push mattrayner/lamp:latest-1404
26-
- docker push mattrayner/lamp:latest
2726
dev:
2827
branch: develop
2928
commands:
3029
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
30+
- docker tag ci_web1604:latest mattrayner/lamp:dev
31+
- docker tag ci_web1604:latest mattrayner/lamp:dev-1604
32+
- docker tag ci_web1404:latest mattrayner/lamp:dev-1404
3133
- docker push mattrayner/lamp:dev-1604
3234
- docker push mattrayner/lamp:dev-1404
3335
- docker push mattrayner/lamp:dev

docker-compose.test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sut:
2+
build: tests/.
3+
dockerfile: Dockerfile.test
4+
links:
5+
- web1604
6+
- web1404
7+
web1604:
8+
build: .
9+
dockerfile: Dockerfile
10+
ports:
11+
- "3000:80"
12+
web1404:
13+
build: .
14+
dockerfile: Dockerfile1404
15+
ports:
16+
- "3001:80"

tests/1404.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
#!/bin/bash
22
source _helpers.sh
33

4-
echo "=> Querying image"
5-
mkdir -p actual/
6-
curl --retry 10 --retry-delay 5 -o actual/1404.html --silent http://localhost:3001 --stderr -
7-
checkstatus $?
8-
9-
echo "=> Checking against expected values"
10-
diff -q -b actual/1404.html expected/1404.html
11-
checkstatus $?
4+
testimage 1404 web1404

0 commit comments

Comments
 (0)