Process record of setting up Apache+php+mysql environment under Docker

Source: Internet
Author: User
Tags install php centos server docker ps docker run

Process record of setting up Apache+php+mysql environment under Docker

This is a process record for setting up a Docker environment for easy viewing later. The main records are the tools used to build, the commands used and the pits encountered.

1. Installing Docker

The first step must be to the Docker's official website (https://www.docker.com) to download the installation package, currently has CE and EE two versions, simply speaking, CE is free version, EE is paid version. Because I'm using a Windows system, here's just how to install it on a Windows system.

You can also click here to download the Windows version directly. Run the installation after you are done.

Because Docker uses the virtualization technology of the CPU, before running it, go into the BIOS and set the Intel Virtual technology in the CPU option to enable.

Finally, you can run Docker directly.

2. Build the CentOS Server environment 2.1 Verify that Docker is started

Open cmd, enter

docker version

If the output version information is indicated, the Docker boot succeeds.

2.2 Fetching the CentOS image

Input command

docker pull centos

The above command will go to the Docker official repository to download the latest CentOS image, but it will be slow to download because it is a foreign site. This can be accelerated using a domestic mirror.

docker pull registry.docker-cn.com/library/centos

When you use mirroring to speed up the download of a mirror, you must enter the full library name and the mirror name.

Since CentOS7 has a dbus bug on Docker, it is recommended to download the CentOS6 image. Just add tag after the image name.

docker pull registry.docker-cn.com/library/centos:6
2.3 Running the CentOS container

After the image is downloaded, enter the command.

docker images

You can see that there is already a mirror.

Then use this image to run a container

docker run -it -p 2222:22 -p 8888:80 609c1f9b5406 /bin/bash
    • -itIndicates that the container is running using terminal mode
    • -p 2222:22Indicates that the 22 port in the container is mapped to the 2222 port of the host
    • 609c1f9b5406ID representing the mirror
    • /bin/bashRepresents the program to execute after the mirror runs

You can see that the command prompt has become a Linux style, indicating that CentOS has been successfully run in the container.

2.4 Installing MySQL
yum install mysqlyum install mysql-serverchkconfig mysqld on         // 设置开机启动service mysqld start        // 启动mysql服务

Then initialize the configuration of MySQL

mysql_secure_installation
2.5 Installing Apache
yum install httpdchkconfig httpd on      // 设置开机启动service httpd start     // 启动apache服务

At this point, http://localhost:8888 you can see the Apache welcome page by accessing it on the host's browser.

2.6 Installing PHP
yum install phpyum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

Write a script and test it.

vi /var/www/html/info.php

Input

<?php    phpinfo();?>

Access http://localhost:8888/info.php , you can see both the PHP information.

3. Save the configured image

Press to Ctrl+D exit bash without ending the container process, then go back to the Windows command line and enter

docker ps

View the container information that is running.

The container ID is then given by the above command to commit the change to the container,

docker commit 1cd1b30fce5e centos-lamp

At the very end is the name given to this new mirror.

Execute the command again

docker images

As you can see, there is a mirror called Centos-lamp.

PS: The method to save the image still has problems, later to study. Just look at the steps to build the environment.

Process record of setting up Apache+php+mysql environment under Docker

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.