How can I develop a Docker application with PHP + MySQL?

Source: Internet
Author: User
Tags php mysql php mysql extension

20141206234218_104.png (170.93 KB, Downloads: PNS)

Download attachments

2015-7-30 17:39 upload

In the process of development, only a technology is certainly not a drop, a lot of application development needs to apply to the multi-door technology. Today we are going to talk to you about how to build a Linux + Apache + MySQL + PHP application based on the lamp technology stack with a Docker image. 1, create the PHP development application container First, select the official PHP image as the base image of the project. Dockerfilefromdaocloud.io/php:5.6-apache then, use the official PHP image built-in command docker-php-ext-install install PHP MySQL extension dependency. Dockerfilerundocker-php-ext-install Pdo_mysql dependent packages are installed through Docker-php-ext-install, if the dependent packages require configuration parameters Docker-php-ext-configure command. Install the Pdo_mysql PHP extension. Then, copy the code to the destination directory. Dockerfilecopy./var/www/html/this can be omitted because the exposed port and the start command have been declared within the underlying image. Now, the Docker container that contains the PHP application development is ready. The parameters required to access the database in PHP code are declared by reading the environment variables. "PHP $serverName =env (" mysql_port_3306_tcp_addr "," localhost "), $databaseName = env (" Mysql_instance_name "," Homestead "), $username = env (" Mysql_username "," Homestead "), $password =env (" Mysql_password "," secret "); /*** GET environment variable * @param $key * @param null$default* @returnnull |string*/functionenv ($key, $default = null) {$value =getenv ($ke Y), if ($value ===false) {return $default; Www.maiziedu.com}return $value;} "Why did you do this?" Because in the best practice of Docker application development, stateful data services are often placed in anothercontainer, and the application container is dynamically connected to the data container through a container-specific link mechanism. 2. Bind the MySQL data container first, you need to create a MySQL container. Bashdocker run--name some-mysql-e mysql_root_password=my-secret-pw-d daocloud.io/mysql:5.5, through the link mechanism between Docker containers, you can Expose MySQL's default port (3306) to the application container. Bashdocker run--name some-app--link some-mysql:mysql-d app-that-uses-mysql 3, cloud-bound MySQL data service creates and binds MySQL in the cloud compared to local creation Data services are much simpler. A, Fork daocloud/php-apache-mysql-sample on GitHub or add your own code warehouse. B, registered as a Daocloud user. C, select Code build in the daocloud"console. D. Create a new project, select a code source, and start building the image. E. Create a MySQL service instance in "service integration". F, associate the built app image with the MySQL service instance and deploy it in the cloud. The above is through the PHP + MySQL implementation of the Docker application of the specific steps, and unclear pro, you can test a.


Recommended Learning: PHP Video Tutorial http://www.maiziedu.com/course/php/
  • 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.