Run PerconaServer with Docker

Source: Internet
Author: User
Tags mysql command line percona percona server docker run

Run PerconaServer with Docker
Run Percona Server with Docker

Percona officially provides a Percona Docker image to run Percona Server MySQL and Percona Server for MongoDB.
Docker also provides an official Percona image. For details, see Percona. However, this image is not officially provided by Percona.
Percona provides official images for each storage engine. For details, see:
Https://hub.docker.com/r/percona/
However, the official image provided by Percona is currently in the experimental stage.

1. Run the Percona Server/MySQL Image
docker run --name container-name -e MYSQL_ROOT_PASSWORD=secret -d percona/percona-server:tag

Container-name is the name you give to the container
Secret is the password of the root account of Percona Server
Tag is the Percona version you want to specify. Currently, there are four options: latest, 5.6, 5.6.28, and 5.6.27.

To connect an application from another Docker container to the Percona Server container:
(Assuming Percona uses the default port 3306)

docker run --name app-container-name --link container-name -d app-that-uses-mysql

Connect to the Percona Server container from the MySQL command line client:
(The following command runs the MySQL command line client from another Docker container and then connects to the Percona Server container)

docker run -it --link container-name --rm percona/percona-server:tag mysql -h container-name -P 3306 -uroot -psecret'
2. Run the Percona Server/MongoDB Image

It is very easy to change the storage engine of the image. For example, you can change it to the RocksDB engine as follows:

docker run --name psmdbrocks -d percona/percona-server-mongodb:latest --storageEngine=RocksDB

Or change to PerconaFT storage engine:

docker run --name psmdbperconaft -d percona/percona-server-mongodb:latest --storageEngine=PerconaFT
3. Environment Variables

When starting the Percona Server container, you can use the docker run command line to pass environment variables to adjust the running configuration of the instance. Note that if the container already contains the database data directory, these environment variables will not work, that is, any database pre-existing in the image will invalidate the environment variables. The main environment variables used include the following:

1) MYSQL_ROOT_PASSWORD
It indicates the password of the root Super User of the Percona server.

2) MYSQL_RANDOM_ROOT_PASSWORD
If this value is set to yes, the password of the root Super User of Percona server is generated randomly and will be output to the container console. You can use the docker logs container-name command to find the password.

3) MYSQL_ONETIME_PASSWORD
This is an optional environment variable. If it is set to yes, the password of the root Super User of Percona server will expire once. After logging on to Percona, you must change the password. This feature must be available in versions 5.6 and later.

4) MYSQL_DATABASE
This is an optional environment variable. It indicates that a database with the specified name can be created when the container starts. If both user and password are set, the user will have super permissions on the specified database (equivalent to the grant all command ).
Note: This method should not be used to create a root account.

5) MYSQL_ALLOW_EMPTY_PASSWORD
If this value is set to yes, the password of the root Super User of Percona server can be blank.
It is not recommended.

4. Percona container security

In many scenarios, it is insecure to use the MYSQL_ROOT_PASSWORD environment variable to specify the password of the root Super User. Therefore, we recommend that you use the MYSQL_RANDOM_ROOT_PASSWORD random password environment variable. To make the instance more secure, you can also use the MYSQL_ONETIME_PASSWORD one-time password environment variable.

5. Data Storage

Applications Running in Docker containers can store data in two ways:

1) Let Docker manage the storage of Database Data
By writing database files to the host system disk (using internal volume management), Docker manages the storage of database data. In this method, devicemapper, aufs, overlayfs, and so on have a great impact on performance.

2) create a data directory on the hosted host (outside the container)
Create a data directory outside the container on the hosted host and make the directory visible to the container through mounting. This method makes database files accessible to tools or applications of the host system. This method must be used to ensure that the data directory exists, and the access permission and other security mechanisms must be set correctly. This is usually possible:

Create a data directory on the appropriate volume of the host system, such as/local/datadir to start the container:

.

docker run --name container-name -v /local/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=secret -d percona/percona-server:tag

The-v parameter indicates that the/local/datadir directory is mounted from the host system to the/var/lib/mysql directory in the container. It is the location where MySQL writes data files.

Note whether the directory of the host system has the write permission on the container. SELinux must enable this permission and execute:

chcon -Rt svirt_sandbox_file_t /local/datadir

If the MySQL container instance is started to use an existing data directory (that is, the database already exists), The MYSQL_ROOT_PASSWORD variable should be omitted when running the docker run Command.

6. port forwarding

Docker allows port ing in the container to the host system port. Use the-p option.

docker run --name container-name `-p 6603:3306` -d percona/percona-servermysql -h docker_host_ip -P 6603

In this way, you can use port 6603 of the host to connect to the MySQL container.

7. Pass parameters to the MySQL container

You can also pass any parameter to the MySQL container in the docker run Command.

docker run --name my-container-name -d percona/percona-server --option1=value --option2=value

Option1 and option2 are passed to the Percona container at container startup. For example, if you want the container to use the UTF-8 as the default setting for character sets and collation, you can do this:

docker run --name container-name -d  percona/percona-server --character-set-server=utf8 --collation-server=utf8_general_ci
8. Use the custom MySQL configuration file

The MySQL container STARTUP configuration file is/var/lib/mysql/my. cnf. to customize this configuration file, you can modify it.

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.