How to develop a PHP Docker application (2)

Source: Internet
Author: User
Tags php cli
How to develop a PHP Docker application (2) Welcome to the "PHP application Docker development package-Powered by DaoCloud 」, we have prepared six series of carefully designed articles for PHP developers. This is the first article in this series.

Objective: to develop a Docker-based sample PHP application based on the basic Docker image of PHP.

This project code is maintained inDaoCloud/php-sampleProject.

Key elements of Docker applications

* An image is a static representation of a Docker application and a delivery of an application. The image contains all the dependencies required for running the application, including the application code, application dependency Library, application runtime, and operating system.

* Dockerfile is a description file that describes the process of generating a Docker image. For more information, see Dockerfile.

* The container is a dynamic representation of the image running. if you think of the image as a Class, the container is the instance of this Class.

The first step of dockerization is to use Dockerfile to generate an application image.

Write Dockerfile

> This basic image uses the official PHP image. you can also use a custom PHP basic image based on your project requirements and environment dependencies.

Because all official images are located on servers outside China, DaoCloud provides a set of domestic image sources to ensure normal operation of all examples, and keeps them in sync with official sources.

Official images maintain all basic PHP images starting with version 5.4. all images use debian: jessie as the system images.

First, select the official php: 5.6-cli image as the basic image of the project.

Dockerfile
FROM daocloud. io/php: 5.6-cli

Because the sample code is relatively simple, we use a Docker image that only installs php cli to run it.

Next, copy the code to the target directory.

Dockerfile
COPY./app
WORKDIR/app
CMD ["php", "./hello. php"]

The difference between "ADD" and "COPY" is that "ADD" and "COPY" are all file adding operations. "ADD" has more functions than "COPY", and "ADD" allows the following parameters to be URLs, if the file added by ADD is a compressed package, it will be automatically decompressed.

CMD is the default command executed when the created image is run. you can modify the default command by running the docker run command.

For the Dockerfile syntax, see:Dockerfile.

With Dockerfile, we can run the following command to build a PHP application image and name it my-php-app:

Docker build-t my-php-app.

Finally, let's start the container from the image:

Docker run my-php-app
Nohighlight
Welcome the world of Docker!

If you see this string, it means you have successfully entered a Docker world.

Welcome to the Docker world, which has unexpected highlights!

Original http://dockone.io/article/536

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.