This topic describes how to deploy OceanBase Database in a single-node container environment using Docker.
Notice
The operations described here are designed for learning or testing purposes only and should not be applied to a production environment.
Prerequisites
Before you start, make sure that the following conditions are met:
You have installed Docker and started the Docker service. For more information, see Docker documentation.
Note
On a Mac with an x86 CPU architecture, you can deploy OceanBase Database only with Docker V4.9.0 or earlier. You can click here to download Docker.
Your server meets the hardware and software requirements. For more information, see Hardware and software requirements.
Deploy OceanBase Database
(Optional) Step 1: Pull the image of OceanBase Database
Run the following commands to pull the image needed for OceanBase Database.
Search for images related to OceanBase Database.
[admin@test001 ~]$ sudo docker search oceanbasePull the latest image of OceanBase Database.
[admin@test001 ~]$ sudo docker pull oceanbase/oceanbase-ceNote
If the Docker image fails to be pulled, you can also pull the image from the quay.io or ghcr.io repository. To do so, replace
oceanbase/oceanbase-cein the above pull command withquay.io/oceanbase/oceanbase-ceorghcr.io/oceanbase/oceanbase-ce.After you change the repository address in the commands of this step, you must also change the repository address in the commands of the next step. The two commands use the same repository address.
By default, the above command pulls the latest version of image. You can select a desired image from dockerhub, quay.io, or ghcr.io according to your needs.
Step 2: Start an OceanBase Database instance
Run the following command to start an OceanBase Database instance.
[admin@test001 ~]$ sudo docker run -p 2881:2881 -v $PWD/ob:/root/ob -v $PWD/obd/cluster:/root/.obd/cluster --name obstandalone -e MODE=NORMAL -e OB_TENANT_PASSWORD=***** -d oceanbase/oceanbase-ce
[admin@test001 ~]$ sudo docker run -p 2881:2881 -v $PWD/ob:/root/ob -v $PWD/obd/cluster:/root/.obd/cluster --name obstandalone -e MODE=MINI -e OB_TENANT_PASSWORD=***** -d oceanbase/oceanbase-ce
In quick start mode, if you configure tenant and resource-related environment variables, the variables other than OB_TENANT_PASSWORD and OB_SYS_PASSWORD are ignored. The username of the created user tenant is default set to test and cannot be changed.
[admin@test001 ~]$ sudo docker run -p 2881:2881 -v $PWD/ob:/root/ob -v $PWD/obd/cluster:/root/.obd/cluster --name obstandalone -e MODE=SLIM -d oceanbase/oceanbase-ce
In the example, the options are described as follows:
-pis used to map a port of the container to a port on the host. In the example, port2881of the container is mapped to port2881on the host.-vis used to share files or directories between the container and the host for data persistence or configuration sharing. By default, the system deploys OceanBase Database in the/root/obdirectory of the container and saves the configuration in the/root/.obd/clusterdirectory. You can use the-voption to persist data on the host.You can also use the
-voption to mount an SQL script for execution. Remember to modify{init_sql_folder_path}in the following example to the actual path of the initialization SQL script.[admin@test001 ~]$ sudo docker run -p 2881:2881 -v {init_sql_folder_path}:/root/boot/init.d --name obstandalone -e MODE=SLIM -d oceanbase/oceanbase-ce--nameis used to set the name of the Docker container, for example,obstandalonein the above example.-eis used to set environment variables. In the example,MODEspecifies the startup mode of OceanBase Database, andOB_TENANT_PASSWORDsets the password of the root@test user in OceanBase Database. For more information about environment variables, see Supported environment variables.
Note
By default, Docker enables the enable_rich_error_msg parameter when it starts. If an error occurs, you can use the trace command to obtain detailed error information.
The startup is expected to take 2 to 5 minutes. Run the following command, and if it returns boot success!, the startup was successful.
[admin@test001 ~]$ sudo docker logs obstandalone | tail -1
boot success!
Step 3: Connect to the OceanBase Database instance
The oceanbase-ce image includes OceanBase Deployer (obd) and OceanBase Client (OBClient), which is a command-line client. You can either enter the container and use the obd commands and OBClient to manage and connect to the instance, or you can connect to the OceanBase Database instance from your host machine using a local OBClient or a MySQL client.
Connect to the instance after you enter the container
Enter the Docker container.
[admin@test001 ~]$ sudo docker exec -it obstandalone bashView the details of the cluster.
# View the list of clusters obd cluster list # View the details of the obcluster cluster obd cluster display obclusterConnect to the cluster.
obclient -h127.0.0.1 -uroot@sys -A -Doceanbase -P2881 -p
Connect to the instance from your host machine
You can connect to the OceanBase Database instance from your host machine using a local OBClient or a MySQL client. Here is an example of connecting to the instance using a local OBClient:
[admin@test001 ~]$ obclient -uroot@sys -h127.0.0.1 -P2881 -p
Note
If you do not configure the password through an environment variable when you start the OceanBase Database instance, the default password is empty for the user created in the instance.
After the connection is established, your terminal will display the following message:
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3221711319
Server version: OceanBase_CE 4.3.0.1 (r100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9) (Built Mar 22 2024 13:19:48)
Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [(none)]>
Supported environment variables
Variable |
Default value |
Value description |
Description |
|---|---|---|---|
| MODE | MINI |
NoteIf |
Set the cluster startup mode. |
| EXIT_WHILE_ERROR | true |
|
Control whether to exit the container when OceanBase Database fails to start. |
| OB_CLUSTER_NAME | obcluster | None | Set the OceanBase cluster name. |
| OB_TENANT_NAME | test | The tenant name must be 63 bytes or less in length and can contain only uppercase and lowercase English letters, numbers, and underscores, and cannot be an OceanBase keyword. | After configuration, a MySQL tenant with the same name is created in the OceanBase cluster. If not configured, the default tenant named test is created.
NoteIf |
| OB_MEMORY_LIMIT | 6G | [6G, +∞) | Set the total memory size available to the OceanBase cluster. It is equivalent to the memory_limit parameter in the other two solutions. |
| OB_DATAFILE_SIZE | 5G | [5G, +∞) | Set the size of data files in the OceanBase cluster. It is equivalent to the datafile_size parameter in the other two solutions. |
| OB_LOG_DISK_SIZE | 5G | [5G, +∞) | Set the size of the redo log disk in the OceanBase cluster. It is equivalent to the log_disk_size parameter in the other two solutions. |
| OB_SYS_PASSWORD | Not set | It must be a non-empty string. | Set the password of the administrator user (root@sys) in the sys tenant of the OceanBase cluster. |
| OB_TENANT_PASSWORD | Not set | It must be a non-empty string. | Set the password of the administrator user in the OB_TENANT_NAME tenant. If OB_TENANT_NAME is not configured, the default value root@test is used. |
| OB_SYSTEM_MEMORY | 1G | [1G, +∞) | Set the memory size reserved for tenant ID 500 in the OceanBase cluster. It is equivalent to the system_memory parameter in the other two solutions. |
| OB_TENANT_MIN_CPU | Not set | Not involved. | Set the minimum CPU specifications of the OB_TENANT_NAME tenant in the OceanBase cluster. If not configured, the tenant will occupy all the remaining resources of the OceanBase cluster. It is equivalent to the MIN_CPU parameter in a resource unit. For more information, see CREATE RESOURCE UNIT. |
| OB_TENANT_MEMORY_SIZE | Not set | Not involved. | Set the memory specifications of the OB_TENANT_NAME tenant in the OceanBase cluster. If not configured, the tenant will occupy all the remaining resources of the OceanBase cluster. It is equivalent to the MEMORY_SIZE parameter in a resource unit. For more information, see CREATE RESOURCE UNIT. |
| OB_TENANT_LOG_DISK_SIZE | Not set | Not involved. | Set the size of the log disk of the OB_TENANT_NAME tenant in the OceanBase cluster. If not configured, the tenant will occupy all the remaining resources of the OceanBase cluster. It is equivalent to the LOG_DISK_SIZE parameter in a resource unit. For more information, see CREATE RESOURCE UNIT. |
| OB_CONFIGSERVER_ADDRESS | Not set | Not involved. | Set the address of obconfigserver. For example: http://10.10.10.1:8080. |
