19-docker Network Fifth Lecture-substituting "--link" (Docker series)

Source: Internet
Author: User
Tags wordpress database docker run

This article is from the "Knowledge Forest"

In the previous explanation "09-docker run Wordpress+mysql Fast build Web site (Docker series)" described the use of --link way to let Wordpress and MySQL container, which is about to become obsolete and needs to be replaced by a Docker network method.

The following is the way to update the Web site in the 09-docker run Wordpress+mysql Quick Build Web site (Docker series) to Docker network. Create a network

Docker Network Create Wp-net
Start the MySQL database
Docker run-d-P 3306:3306--name wp-mysql--network wp-net--network-alias mysql-e mysql_root_password=123 MySQL

Description:

Docker run: Launch container

-D: Background run

-P 3,306:3,306: Map the container's 3306 ports to the host's 3306 port

--name Wp-mysql: The name of the specified container is Wp-mysql

--network wp-net: Adding containers to the Wp-net network

--network-alias MySQL: Specifies that the container alias in the Wp-net network is MySQL

-E mysql_root_password=123: Initialize database ROOT password 123 start wordpress site Program

Docker run-d-P 80:80--name wp-web--network wp-net--network-alias wordpress-e wordpress_db_password=123 WordPress

Description:

Docker run: Launch container

-D: Background run

-P 80:80: Maps 80 ports in a container to the host's 80 port

--name Wp-web: The name of the specified container is Wp-web

--network wp-net: Adding containers to the Wp-net network, in the same network as the MySQL database

--network-alias WordPress: Specify the container in the network alias is WordPress, this can not, because in other containers do not need this name

-E wordpress_db_password=123: Specify WORDPRESS Database Password authentication to communicate with database in Wp-web container

C:\users\zsl-pc>docker exec-it wp-web/bin/bash
root@202fdad27426:/var/www/html# ping-w 2 mysql
ping MySQL (172.19.0.2): Data bytes bytes from 172.19.0.2:icmp_seq=0 ttl=64 time=0.049 ms-bytes from
172.19.0.2:ic Mp_seq=1 ttl=64 time=0.155 ms
---mysql ping statistics---
3 packets transmitted, 2 packets received, 33% packet Loss
Round-trip Min/avg/max/stddev = 0.049/0.102/0.155/0.053 ms

Description: describes the ability to use the MySQL database in the Wp-web container. View host IP and test access

C:\users\zsl-pc>docker-machine IP tmp-machine
192.168.99.100

the host's IP address is 192.168.99.100, because 80 ports in the Wp-web container have been mapped to the host 80 port, so we can enter this IP address directly in the browser to access.

specific access and use can be parameter article "09-docker Run Wordpress+mysql Fast build Web site (Docker series)"

The site has been working properly and has not used--link to communicate between containers, so we have successfully changed the way the container communicates to Docker network.

This article is from the "Knowledge Forest"

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.