Exchange of visits between two containers in Docker

Source: Internet
Author: User
Tags mysql client docker run

In the previous articles, we discussed how to install Docker in Ubuntu14.04 (64-bit) and how to deploy an Apache server in Docker and access the server on an external computer, and deploy in Docker

A MySQL database and access the database on an external computer.

The following is a discussion of the Docker between the containers, mainly in two containers between the MySQL database exchange visits as an example.


Sometimes, there is a need to communicate between two startup containers, such as we run an Apache server in a container with a Web site, and then the database of the site can be deployed in another container. Or two containers have a database deployed, and then the two databases need to communicate.

Here's an example of a container that accesses a MySQL database for another container.

The access between containers is mainly done through-link parameters.

First, follow the previous tutorial to install the XAMPP in a mirror.

Then start the mirror and name the startup container server as the MySQL server:

sudo docker run–i–t–p–-name=server Ubuntu2/bin/bash

(Note that P is uppercase)

Start MySQL after entering the command line on container server

/opt/lampp/lampp start

Open another command line terminal on the local computer, run another container, act as a MySQL client, and access the MySQL database in the container server:

sudo  docker run–i–t–p  --link=server:db–name=client Ubuntu2/bin/bash

(Note that P is uppercase)

--link=server:db said that the server container was renamed to DB, and then you could access the server container in the client container above.

In the container client command line, start MySQL:

/opt/lampp/lampp  Start
Then access the MySQL database in the server container
MySQL-  h db–u Root

(Note that the value after-H corresponds to the value in Link=server:db)

Here, the client connects to the MySQL database on the server container.

What databases are you looking at:

show databases;

Then create a new database:

Create  database hehe;

Then go back to the command line in the server container and enter MSYQL:

Mysql–u Root

See which databases are available:

show databases;

You should see hehe at this point. Indicates that the connection on the client container is indeed a MySQL database in the server.

Here, the communication between the containers is over.

Problems:

1. Error occurred lost connection to MySQL server:

Workaround:

First into the directory (if your MySQL is installed via XAMPP)/opt/lampp/etc:


Cd/opt/lampp/etc

Then use VIM to open my.cnf and find this line:

Bind-address = 127.0.0.1

Comment It out and ignore it if it is not.

Then find the parameters in the [mysqld] section, create a new line after the configuration, and add the following parameter:

Skip-name-resolve
Save and exit.

Then restart XAMPP:

/OPT/LAMPP/LAMPP restart

It should be settled here.

If your MySQL is not installed through the XAMPP, then my.cnf generally will only be stored in the/etc/my.cnf or/etc/mysql/my.cnf;

Change the my.cnf to the same as above, and then restart MySQL:

/etc/init.d/mysql restart

2. Host IP isn't allowed to connet to this MySQL server error

Workaround:

Enter MySQL:

Mysql-u Root

Then authorize the other user:


Grant all privileges in *.* to ' root ' @ '% ' with GRANT OPTION;

FLUSH privileges;

It should be settled here.

If it is also resolved, please refer to here: http://joinyo.iteye.com/blog/1489380

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.