Use Docker

Background

This chapter is an introduction about how to start ShardingSphere-Proxy via Docker

Notice

Using Docker to start ShardingSphere-Proxy does not require additional package supoort.

Steps

  1. Acquire Docker Image
  • Method 1 (Recommended): Pull from DockerHub
  1. docker pull apache/shardingsphere-proxy
  1. git clone https://github.com/apache/shardingsphere
  2. ./mvnw clean install
  3. cd shardingsphere-distribution/shardingsphere-proxy-distribution
  4. ./mvnw clean package -Prelease,docker

If the following problems emerge, please make sure Docker daemon Process is running.

  1. I/O exception (java.io.IOException) caught when processing request to {}->unix://localhost:80: Connection refused?
  1. Configure conf/global.yaml and conf/database-*.yaml

Configuration file template can be attained from the Docker container and can be copied to any directory on the host:

  1. docker run -d --name tmp --entrypoint=bash apache/shardingsphere-proxy
  2. docker cp tmp:/opt/shardingsphere-proxy/conf /host/path/to/conf
  3. docker rm tmp

Since the network conditions inside the container may differ from those of the host, if errors such as “cannot connect to the database” occurs, please make sure that the IP of the database specified in the conf/database-*.yaml configuration file can be accessed from inside the Docker container.

For details, please refer to ShardingSphere-Proxy quick start manual - binary distribution packages.

  1. (Optional) Introduce third-party dependencies or customized algorithms

If you have any of the following requirements:

  • ShardingSphere-Proxy Backend use MySQL Database;
  • Implement customized algorithms;
  • Use Etcd as Registry Center in cluster mode.

Please create ext-lib directory anywhere inside the host and refer to the steps in ShardingSphere-Proxy quick start manual - binary distribution packages.

  1. Start ShardingSphere-Proxy container

Mount the conf and ext-lib directories from the host to the container. Start the container:

  1. docker run -d \
  2. -v /host/path/to/conf:/opt/shardingsphere-proxy/conf \
  3. -v /host/path/to/ext-lib:/opt/shardingsphere-proxy/ext-lib \
  4. -e PORT=3308 -p13308:3308 apache/shardingsphere-proxy:latest

ext-lib is not necessary during the process. Users can mount it at will. ShardingSphere-Proxy default portal 3307 can be designated according to environment variable -e PORT Customized JVM related parameters can be set according to environment variable JVM_OPTS

Note:

Support setting environment variable CGROUP_ MEM_ OPTS: used to set related memory parameters in the container environment. The default values in the script are:

  1. -XX:InitialRAMPercentage=80.0 -XX:MaxRAMPercentage=80.0 -XX:MinRAMPercentage=80.0
  1. Use Client to connect to ShardingSphere-Proxy

Please refer to ShardingSphere-Proxy quick start manual - binary distribution packages.