Logo
Use Docker

Use Docker #

Background #

This chapter introduces how to start DBPlusEngine-Proxy via Docker.

Notice #

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

Steps #

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

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

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

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

docker run -d --name tmp --entrypoint=bash apache/shardingsphere-proxy
docker cp tmp:/opt/shardingsphere-proxy/conf /host/path/to/conf
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” occur, please make sure that the IP of the database specified in the conf/config-*.yaml configuration file can be accessed from inside the Docker container.

For details, please refer to DBPlusEngine-Proxy quick start manual - Use Binary Tar.

  1. Start the DBPlusEngine-Proxy container

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

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

ext-lib is not necessary during the process. Users can mount it at will. DBPlusEngine-Proxy default port 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:

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

Please refer to DBPlusEngine-Proxy quick start manual - Use Binary Tar.

Configuration Example #

For full configuration, please refer to the examples given in DBPlusEngine library: https://github.com/apache/shardingsphere/tree/master/examples/shardingsphere-proxy-example.