You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
-[`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)
28
43
29
44
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
30
45
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.
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
45
71
```
46
72
47
-
### Using with a Dockerfile
48
-
```
49
-
FROM mattrayner/lamp:latest
73
+
### With a Dockerfile
74
+
```docker
75
+
FROM mattrayner/lamp:latest-1604
50
76
51
77
# Your custom commands
52
78
53
79
CMD ["/run.sh"]
54
80
```
55
81
56
-
### MySQL
57
-
The defaultimage 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.
58
84
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 3306using 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.
60
86
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.
62
88
63
89
#### Creating a database
64
90
So your application needs a database - you have two options...
91
+
65
92
1. PHPMyAdmin
66
93
2. Command line
67
94
68
95
##### 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.
70
99
71
100
##### Command Line
72
101
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
75
103
docker exec CONTAINER_ID mysql -uroot -e "create database DATABASE_NAME"
76
104
```
77
105
78
106
79
107
## 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.
81
109
82
110
The below examples assume the following project layout and that you are running the commands from the 'project root'.
83
-
84
111
```
85
112
/ (project root)
86
113
/app/ (your PHP files live here)
114
+
/mysql/ (docker will create this and store your MySQL data here)
87
115
```
88
116
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.
90
118
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
93
122
docker run -i -t -p "80:80" -v ${PWD}/app:/app mattrayner/lamp
94
123
```
95
124
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
-
98
125
### 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
100
130
docker run -i -t -p "80:80" -v ${PWD}/mysql:/var/lib/mysql mattrayner/lamp
101
131
```
102
132
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.
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.
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
-
114
139
#### `.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)
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)";
133
205
```
134
206
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
+
135
238
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].
0 commit comments