Example Dockerfile for deploying a CakePHP application in a Docker container, able to connect to a remote database with database-based sessions.
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.
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:
docker build -t myvendor/mycakephpapp .
Optional: You can now push your new image to a registry:
docker push myvendor/mycakephpapp
Start your image forwarding container port 80 to localhost port 80:
docker run -d -p 80:80 myvendor/mycakephpapp
Start a MySQL container
docker run -d \
--name mysql-server \
-e MYSQL_ROOT_PASSWORD=sekret \
-e MYSQL_DATABASE=cakephp \
mysql:5.7
Start your image and:
database
session handler using our the SESSION_DEFAULTS env variable (see Dockerfile
for implementation)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
Visit http://localhost/
in your browser or
curl http://localhost/
You can now start using your CakePHP container!
Dockerfile
to sed
the config/app.php
file to use the database or cache session handler as implemented in the example.volumes
or an object storage with a webservice interface like Amazon S3.