Giter Site home page Giter Site logo

dagelf / docker-cakephp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stefanvangastel/docker-cakephp

0.0 1.0 0.0 24 KB

Example Dockerfile for deploying a CakePHP application in a Docker container, able to connect to a remote database with database-based sessions.

License: MIT License

Dockerfile 100.00%

docker-cakephp's Introduction

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:

docker build -t myvendor/mycakephpapp .

Optional: You can now push your new image to a registry:

docker push myvendor/mycakephpapp

Running your CakePHP docker image

Start your image forwarding container port 80 to localhost port 80:

docker run -d -p 80:80 myvendor/mycakephpapp

Example: Connecting to a MySQL container

Start a MySQL container

docker run -d \
	--name mysql-server \
	-e MYSQL_ROOT_PASSWORD=sekret \
	-e MYSQL_DATABASE=cakephp \
	mysql:latest

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)
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 or an object storage with a webservice interface like Amazon S3.

docker-cakephp's People

Contributors

stefanvangastel avatar sux2mfgj avatar

Watchers

Coenraad Loubser avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.