Docker
Use docker-compose utility to create and manage YugabyteDB local clusters. Note that this approach is not recommended for multi-node clusters used for performance testing and production environments. Refer to the deployment checklist to understand the configuration to create clusters.
Prerequisites
Make sure to have Docker installed on your machine.
1. Create a single node cluster
Pull the container
Pull the container from Docker Hub registry.
$ docker pull yugabytedb/yugabyte
Create a docker-compose.yaml
file
version: '2'
volumes:
yb-master-data-1:
yb-tserver-data-1:
services:
yb-master:
image: yugabytedb/yugabyte:latest
container_name: yb-master-n1
volumes:
- yb-master-data-1:/mnt/master
command: [ "/home/yugabyte/bin/yb-master",
"--fs_data_dirs=/mnt/master",
"--master_addresses=yb-master-n1:7100",
"--rpc_bind_addresses=yb-master-n1:7100",
"--replication_factor=1"]
ports:
- "7000:7000"
environment:
SERVICE_7000_NAME: yb-master
yb-tserver:
image: yugabytedb/yugabyte:latest
container_name: yb-tserver-n1
volumes:
- yb-tserver-data-1:/mnt/tserver
command: [ "/home/yugabyte/bin/yb-tserver",
"--fs_data_dirs=/mnt/tserver",
"--start_pgsql_proxy",
"--rpc_bind_addresses=yb-tserver-n1:9100",
"--tserver_master_addrs=yb-master-n1:7100"]
ports:
- "9042:9042"
- "5433:5433"
- "9000:9000"
environment:
SERVICE_5433_NAME: ysql
SERVICE_9042_NAME: ycql
SERVICE_6379_NAME: yedis
SERVICE_9000_NAME: yb-tserver
depends_on:
- yb-master
Start the cluster
$ docker-compose -f ./docker-compose.yaml up -d
2. Initialize the APIs
YCQL and YSQL APIs are enabled by default on the cluster.
3. Test the APIs
Clients can now connect to the YSQL API at localhost:5433 and the YCQL API at localhost:9042. The yb-master admin service is available at http://localhost:7000.
Connect to YSQL
$ docker exec -it yb-tserver-n1 /home/yugabyte/bin/ysqlsh -h yb-tserver-n1
ysqlsh (11.2-YB-2.0.11.0-b0)
Type "help" for help.
yugabyte=# CREATE TABLE foo(bar INT PRIMARY KEY);
Connect to YCQL
$ docker exec -it yb-tserver-n1 /home/yugabyte/bin/ycqlsh yb-tserver-n1
Connected to local cluster at yb-tserver-n1:9042.
[ycqlsh 5.0.1 | Cassandra 3.9-SNAPSHOT | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
ycqlsh>
ycqlsh> CREATE KEYSPACE mykeyspace;
ycqlsh> CREATE TABLE mykeyspace.foo(bar INT PRIMARY KEY);
ycqlsh> DESCRIBE mykeyspace.foo;
Connect with an application client
Here is an example of a client that is defined within the same Docker Compose file.
version: '2'
volumes:
yb-master-data-1:
yb-tserver-data-1:
networks:
dbinternal:
dbnet:
services:
yb-master:
image: yugabytedb/yugabyte:latest
container_name: yb-master-n1
networks:
- dbinternal
volumes:
- yb-master-data-1:/mnt/master
command: [ "/home/yugabyte/bin/yb-master",
"--fs_data_dirs=/mnt/master",
"--master_addresses=yb-master-n1:7100",
"--rpc_bind_addresses=yb-master-n1:7100",
"--replication_factor=1"]
ports:
- "7000:7000"
environment:
SERVICE_7000_NAME: yb-master
yb-tserver:
image: yugabytedb/yugabyte:latest
container_name: yb-tserver-n1
networks:
- dbinternal
- dbnet
volumes:
- yb-tserver-data-1:/mnt/tserver
command: [ "/home/yugabyte/bin/yb-tserver",
"--fs_data_dirs=/mnt/tserver",
"--start_pgsql_proxy",
"--rpc_bind_addresses=yb-tserver-n1:9100",
"--tserver_master_addrs=yb-master-n1:7100"
]
ports:
- "9042:9042"
- "5433:5433"
- "9000:9000"
environment:
SERVICE_5433_NAME: ysql
SERVICE_9042_NAME: ycql
SERVICE_6379_NAME: yedis
SERVICE_9000_NAME: yb-tserver
depends_on:
- yb-master
yb-client:
image: yugabytedb/yb-sample-apps:latest
container_name: yb-client-n1
networks:
- dbnet
command: [ "--workload", "SqlInserts", "--nodes", "yb-tserver-n1:5433" ]
depends_on:
- yb-tserver
For more examples, follow the instructions in the Quick Start section with Docker.
4. Stop the cluster
$ docker-compose -f ./docker-compose.yaml down