Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stefanvangastel/docker-cakephp
Example Dockerfile for deploying a CakePHP application in a Docker container, able to connect to a remote database with database-based sessions.
https://github.com/stefanvangastel/docker-cakephp
cakephp cakephp-application docker docker-cakephp docker-container dockerfile mysql-container ubuntu
Last synced: 3 months ago
JSON representation
Example Dockerfile for deploying a CakePHP application in a Docker container, able to connect to a remote database with database-based sessions.
- Host: GitHub
- URL: https://github.com/stefanvangastel/docker-cakephp
- Owner: stefanvangastel
- License: mit
- Created: 2014-08-27T14:17:50.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-11-09T09:48:10.000Z (almost 5 years ago)
- Last Synced: 2024-04-11T08:32:54.299Z (7 months ago)
- Topics: cakephp, cakephp-application, docker, docker-cakephp, docker-container, dockerfile, mysql-container, ubuntu
- Language: Dockerfile
- Homepage:
- Size: 25.4 KB
- Stars: 31
- Watchers: 9
- Forks: 27
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cakephp - Docker - CakePHP in a docker container environment. (Development Environment)
README
docker-cakephp
======================Dockerfile for deploying your CakePHP application in a Docker container, able to connect to a remote database with database-based sessions and inject ENV vars to configure your application.
Based on Ubuntu 16.04 Xenial and PHP 7.0
**Note: This project is meant to be an example to study the basics and essentials of CakePHP in a Docker environment, therefore it is build on an Ubuntu base image rather then a PHP base image, uses a 'simple' webserver like Apache and has some non-efficient commands to demonstrate stuff.**
Usage
-----You can edit the `Dockerfile` to add your own git, composer or custom commands to add your application code to the image.
To create the image `myvendor/mycakephpapp`, execute the following command on the docker-cakephp directory:
```bash
docker build -t myvendor/mycakephpapp .
```Optional: You can now push your new image to a registry:
```bash
docker push myvendor/mycakephpapp
```Running your CakePHP docker image
-----------------------------------Start your image forwarding container port 80 to localhost port 80:
```bash
docker run -d -p 80:80 myvendor/mycakephpapp
```Example: Connecting to a MySQL container
-----------------------------------
Start a [MySQL container](https://hub.docker.com/_/mysql/)```bash
docker run -d \
--name mysql-server \
-e MYSQL_ROOT_PASSWORD=sekret \
-e MYSQL_DATABASE=cakephp \
mysql:5.7
```Start your image and:
* Link it to the MySQL container you just started (so your container can contact it)
* Connect to a remote database server using the CakePHP DATABASE_URL env variable filled with the variables given in the command above.
* Use the `database` session handler using our the SESSION_DEFAULTS env variable (see `Dockerfile` for implementation)```bash
docker run -d -p 80:80 \
--name cakephp \
-e "DATABASE_URL=mysql://root:sekret@mysql-server/cakephp?encoding=utf8&timezone=UTC&cacheMetadata=true" \
-e "SESSION_DEFAULTS=database" \
--link mysql-server:mysql \
myvendor/mycakephpapp
```Test your deployment
--------------------------Visit `http://localhost/` in your browser or
curl http://localhost/
You can now start using your CakePHP container!
Things to look out for
-----------------------------------
* Think about handling session when running multiple containers behind a loadbalancer. You could modify the `Dockerfile` to `sed` the `config/app.php` file to use the database or cache session handler as implemented in the example.
* If you want to store any files (e.g. uploads), please remember containers are 'stateless' and the data will be gone when you delete them. You can use [`volumes`](https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-host-directory-as-a-data-volume) or an object storage with a webservice interface like Amazon S3.