Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Just a simple example of how to create a simple PHP application and deploy it with Docker

NotificationsYou must be signed in to change notification settings

kekbait/php-docker-apache-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker run -p 8080:80 -v $(pwd)/myapp:/var/www/html --name le_php php-docker-apache-example ./vendor/bin/phpunit tests/tests.phpdocker build -t php-docker-apache-example .

How does it work?

# build the docker imagedocker build -t php-docker-apache-example.# run the docker container on this machine. Expose its internal# port 80 to this machine's port 8080docker run -d -p 8080:80 php-docker-apache-example

And you can see the result here:screenshot

# to spin up additional containers on different ports, you might# do something like this:docker run -d -p 5000:80 php-docker-apache-exampledocker run -d -p 5001:80 php-docker-apache-exampledocker run -d -p 5002:80 php-docker-apache-exampledocker run -d -p 5003:80 php-docker-apache-exampledocker run -d -p 5004:80 php-docker-apache-exampledocker run -d -p 5005:80 php-docker-apache-exampledocker run -d -p 5006:80 php-docker-apache-exampledocker run -d -p 5007:80 php-docker-apache-example

Now you have 8 concurrent webservers running, all ready to servetraffic on 8 different ports. A load balancer would typicallychoose which container to send a request to based on load /availability / etc.

If you wanted to deploy a new version of your software but are nervousof breaking something, you could spin up new containers and leave theold ones running. If anything bad happens, switching back to the oldcontainers is quick and reliable.

More information

  • The PHP application code goes inmyapp/
  • The first line of the DockerfileFROM php:7.0-apache means "usethe official maintained image (which happens to be debian based)with php version 7 and apache installed on it". When you rebuild yourimages, you get any security updates along with it for free.
  • Developers are typically responsible for creating and maintainingthe Dockerfile and any dependencies their code makes use of (forexample, if they want to use ImageMagick to convert images tothumbnails, they will have to put it in the Dockerfile, otherwisetheir code would break).
  • Applications should avoid writing to the filesystem (when uploadingfiles, for instance) and prefer to use object storage, such asAmazon S3 instead. The reason for this is that it is a maintenanceheadache. It is definitely possible. It is usually more annoyingthan alternatives.
  • In development, the developer would likely also use a docker containerfor MySQL / similar persistent data stores. In production, their Dockercontainer would likely connect to a different (managed) database.

About

Just a simple example of how to create a simple PHP application and deploy it with Docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP100.0%

[8]ページ先頭

©2009-2025 Movatter.jp