Docker Build Lamp Application Example Detailed _docker

Source: Internet
Author: User
Tags curl git clone docker ps docker run

Docker to build lamp application

LAMP refers to the Linux (operating system), Apachehttp Server, MySQL (sometimes referred to as MARIADB, database software) and PHP (sometimes referred to as Perl or Python) The first letter, generally used to build a Web server. Although these open source programs are not specifically designed to work with several other programs, this combination has become popular because of their free and open source (most Linux distributions are bundled with these software). When used together, they act like a dynamic solution package. Here's how to use Docker to build a container that contains lamp components:

Pull a lamp mirror from the web

There is no mirror image of the official lamp in the official warehouse, but the "tutum" mirror is doing very well and we can pull their mirrors directly to complete our operation.

Core@localhost ~/base $ docker Pull Tutum/lamp pulling repository tutum/lamp 4b32789c7d66:download complete
...

Start the lamp container using the default method

Core@localhost ~/base $ docker run-d-P 8080:80-p 3306:3306 tutum/lamp #启动应用并映射 8080 ports and 3306 ports 0ee00c97a5cdefb985baf8        26C16723F333AA5EDDDEE4072A5107C724AD09F10D core@localhost ~/base $ docker ps CONTAINER ID IMAGE COMMAND       CREATED STATUS PORTS NAMES 0ee00c97a5cd tutum/lamp:latest "/run.sh" 3 seconds ago up 2 seconds 0.0.0.0:3306->3306/tcp, 0.0.0.0:8080->80/tcp Lonely_davinci e3c136d76b44 tutum /tomcat:8.0 "/run.sh" minutes ago up minutes 0.0.0.0:80->8080/tcp tomcat001 fe9e                    65aaf58c dl.dockerpool.com:5000/mysql:5.7 "/entrypoint.sh mysq Wuyi minutes ago up" minutes 3306/tcp Db001,tomcat001/tomysql core@localhost ~/base $ curl http://127.0.0.1:8080 #使用curl可以查看到默认的应用已经启动  

Deploy your own PHP application

The default container launches a Helloword application, and we can use Dockerfile to create another mirror to deploy our own application, Dockerfile detailed syntax will be described later in this chapter.

Core@localhost ~ $ mkdir php
core@localhost ~ $ cd php/
core@localhost ~/php $ touch dockerfile
core@localhost ~/php $ VI dockerfile
core@localhost ~/php $ docker build-t Dockerpool/my-lamp-app.

Dockerfile contents are as follows:

From Tutum/lamp:latest
RUN rm-fr/app && git clone https://github.com/username/customapp.git/app
# Here replace the Https://github.com/username/customapp.git address for your own project address
expose 3306
CMD ["/run.sh"]

Start your own container again and complete the deployment

Core@localhost ~/php $ docker Stop  0ee
0ee
core@localhost ~/php $ docker rm 0ee
0ee
Core@localhost ~/php $ docker run-d-P 8080:80-p 3306:3306 Dockerpool/my-lamp-app

Use Curl to see if your application has started correctly!

Curl http://localhost/

Connecting to a database in a PHP program

Accessing the MySQL database in a container

This mirrored MySQL database has a default root user, which can be used without a password when connected locally, so it is very easy to access the code.

<?php
$mysql = new mysqli ("localhost", "root");
echo "MySQL Server Info:". $mysql->host_info;
? >

Accessing the MySQL database outside the container

When we first start the container in Tutum/lamp mirroring, it automatically creates a MySQL user named admin and generates a random password, which can be obtained using the "docker logs + container id".

Core@localhost ~/php $ docker logs 9CB
=> an empty or uninitialized MySQL volume is detected in/var/lib/mysql
=> Installing MySQL ...
=> done!
=> waiting for confirmation to MySQL service startup
=> creating MySQL Admin user with random password
=> done!
========================================================================
can now connect to this MySQL Server Using:

  mysql-uadmin-p2ijg6gvmm0n3-h 
 

The default root user cannot log on remotely, so it also has root permissions to use the Admin user.

Thank you for reading, I hope to help you, thank you for your support for this site!

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.