今回は自由1かつオープンソース2な分散型NoSQLデータベースであるCassandraを使う3。
Docker上にコンテナとしてCassandraをシングルノードで起動し、キースペース、テーブルの作成、データの挿入と照会を行う。Dockerはインストール済みとする。Cassandraのバージョンは 5.0-alpha1
を使う。
簡単な操作
docker pull cassandra:5.0-alpha1
docker run --rm --name cassandra \
--publish 7000:7000 \
--publish 7001:7001 \
--publish 7199:7199 \
--publish 9042:9042 \
--publish 9160:9160 \
cassandra:5.0-alpha1
docker exec -it cassandra cqlsh
WARNING: cqlsh was built against 5.0-alpha1, but this server is 5.0. All features may not work! Connected to Test Cluster at 127.0.0.1:9042 [cqlsh 6.2.0 | Cassandra 5.0-alpha1 | CQL spec 3.4.7 | Native protocol v5] Use HELP for help. cqlsh>
CREATE KEYSPACE test WITH replication = {
'class': 'SimpleStrategy',
'replication_factor' : 1
};
USE test;
CREATE TABLE book (
id text PRIMARY KEY,
title text,
update_time timestamp
) WITH default_time_to_live = 31536000;
INSERT INTO book (
id,
title,
update_time
) VALUES (
'1234',
'yay',
'2023-10-10T00:11:22.001+0000'
);
SELECT * FROM book;
id | title | update_time ------+-------+--------------------------------- 1234 | yay | 2023-10-10 00:11:22.001000+0000 (1 rows)
コンテナイメージについて調べた事
公式のDockerイメージでは、eclipse-temurinがベースイメージとして使用されていた4。