How to develop a PHP application for Docker (ii)

Source: Internet
Author: User
Tags php cli docker run
Welcome to the "php Application Docker development Package-Powered by daocloud", we have six articles for PHP developers with a sophisticated, well-designed series. This article is the 2nd article in this series.

Objective: To develop a Docker sample PHP application based on PHP's Docker base image.

This project code is maintained in the daocloud/php-sample project.

Key elements of Docker applications

* Mirroring is a static representation of Docker applications and is an application deliverable that contains all the dependencies that the app needs to run: Including app code, application-dependent libraries, App runtimes, and operating systems.

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

* The container is a dynamic representation of the image runtime, and if the image is imagined as a class then the container is the instance instance of the class.

One of the first steps in applying Docker is to create an application image through Dockerfile.

Writing Dockerfile

> This basic image uses PHP's official image, or you can use a custom PHP base image based on your own project needs and environment dependencies.

Because all official images are located on an offshore server, Daocloud provides a set of internal mirror sources and synchronizes with the official sources to ensure that all the samples are functioning properly.

The official image maintains all PHP base images since the 5.4 release, all with Debian:jessie as the system image.

First, select the official PHP:5.6-CLI image as the base image for the project.

Dockerfile
From DAOCLOUD.IO/PHP:5.6-CLI

Because the sample code is simpler, we run it with a Docker image that installs only the PHP CLI.

Next, copy the code to the destination directory.

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

The difference between add and copy, in general, add and copy are the operations of adding files, where add more than the copy function, add allows the following parameters for the URL, and add the file as a compressed package, it will be automatically extracted.

CMD is the command that is executed by default when the image is built, and we can modify the default Run command through the Docker Run's start command.

Dockerfile specific Syntax Please refer to: Dockerfile .

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

Docker build-t My-php-app.

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

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 world of Docker, the world has your unexpected wonderful!

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.