Use Docker to build lamp running environment Tutorial detailed _docker

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

Lamp Introduction

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 * * * * * * * *. 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.

"Lang-bash" >core@localhost ~/base $ docker Pull Tutum/lamp pulling repository tutum/lamp b32789c7d66
: Download Complete ...

Start the lamp container using the default method

 "Lang-bash" >core@localhost ~/base $ docker Run "Hljs-operator" >-d-p:-p:tutum/    Lamp ee00c97a5cdefb985baf826c16723f333aa5edddee4072a5107c724ad09f10d core@localhost ~/base $ docker PS CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ee00c97a5 "hljs-built_in" ; CD tutum/lamp:latest "/run.sh" seconds ago up seconds 0.0.0.0:->/tcp, 0.0.0.0:->/tcp Lonel Y_davinci e3c136d76b44 tutum/tomcat: "Hljs-number" >8.0 "hljs-string" > "/run.sh" Minutes ago up M Inutes "Hljs-number" >0.0. "Hljs-number" >0.0:->/tcp tomcat001 fe9e65aaf58c dl.dockerpool.com:/mysql: "Hljs-number" >5.7 "Hlj" S-string ">"/entrypoint.sh mysq minutes ago up Wuyi minutes 3306/tcp db001,tomcat001/tomysql C Ore@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

"Lang-bash" >core@localhost ~/php $ docker Stop  ee
ee
core@localhost ~/php $ docker rm ee
EE
Core@localhost ~/php $ docker Run "Hljs-operator" >-d-p:-p:dockerpool/my-lamp-app

Use Curl to see if your application has started correctly!

Curl http://localhost/

Connect the database in the PHP program to access the MySQL database in the 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.

"Hljs-preprocessor" ><?php
$mysql = "Hljs-keyword" >new mysqli ("hljs-string" > "localhost", " Hljs-string ">" root ");
echo "hljs-string" > "MySQL Server Info:". Hljs-variable "> $mysql" hljs-variable >->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".

"Lang-bash" >core@localhost ~/php $ docker logs CB
=> an empty or uninitialized MySQL volume is detected in/var/ Lib/mysql
=> installing MySQL
... => done!
=> Waiting "Hljs-keyword" >for confirmation of 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.

Summarize

The above is the entire content of this article, I hope the content of this article for everyone to use Docker build lamp can help, if there is doubt you can message exchange.

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.