In this post, I'll be deploying the EventStoreDB database in a Docker container. I'll start by configuring Portainer to make working with containers easier and then deploy and test the EventStoreDB container.
Configuring Portainer
When using Portainer, there are a few settings I like to configure before deploying containers, so I logged into Portainer using the admin account to make the changes.
Setting the Public IP
Portainer allows the user to connect to container ports by clicking on them. However, this behavior requires the setting of the Public IP for the environment. I clicked on the Environment tab and clicked on the local environment to bring up the Environment details page. I then entered the hostname in the Public IP textbox and clicked Update environment... button
Creating My User Account
Even in a home lab, I don't want to run Portainer as the admin user for everyday tasks. Instead, I want to use a user account with fewer privileges for working with containers and only use the admin account for doing maintenance tasks in Portainer.
First, I created a new user by opening the Users tab.
I entered my credentials in the Username and Password textboxes and clicked the Create user button.
Next, I added the new user to the local environment by going to the Environment tab and clicking the Manage access link.
On the Environment access page, I selected the cfarris user I just created, set the Role to Standard User, and clicked the Create access button.
With my user account now created, I logged out of Portainer as admin and logged back in on the new cfarris user account.
Deploying the EventStoreDB Container
The EventStoreDB documentation describes several different methods of deploying the database in a container (https://developers.eventstore.com/server/v20.10/installation.html#docker). My preference is to use Docker Compose and load the file directly from a GitHub repository. I like this approach because it moves the configuration files off of the Docker server and into source control where I can easily track and document changes.
Creating the GitHub Repository
First, I created a new repository in GitHub called eventstoredb-docker
with a blank .gitignore file and a README.md file.
Next, I created a branch and added the docker-compose.yml example from the EventStoreDB installation page.
version: "3.4"
services:
eventstore.db:
image: eventstore/eventstore:20.10.2-buster-slim
environment:
- EVENTSTORE_CLUSTER_SIZE=1
- EVENTSTORE_RUN_PROJECTIONS=All
- EVENTSTORE_START_STANDARD_PROJECTIONS=true
- EVENTSTORE_EXT_TCP_PORT=1113
- EVENTSTORE_HTTP_PORT=2113
- EVENTSTORE_INSECURE=true
- EVENTSTORE_ENABLE_EXTERNAL_TCP=true
- EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP=true
ports:
- "1113:1113"
- "2113:2113"
volumes:
- type: volume
source: eventstore-volume-data
target: /var/lib/eventstore
- type: volume
source: eventstore-volume-logs
target: /var/log/eventstore
volumes:
eventstore-volume-data:
eventstore-volume-logs:
I committed the file and merged the branch into the master
branch.
Deploying using Portainer
Next, I opened the Stacks page from the Portainer dashboard.
I clicked on Add stack to create open the Create stack page.
I entered eventstoredb as the name of my stack in the Name textbox. Portainer supports several methods for supplying the docker-compose.yml file but I'm using a GitHub repository so I selected Repository. Next, I entered the URL of my repository (https://github.com/SleepingBearSystems/eventstoredb-docker.git) in the Repository URL textbox and checked the deployment was using the master branch for the Repository reference textbox and the docker-compose.yml file for the Compose path textbox.
Next, I scrolled to the bottom of the page and disabled Access control since I'm the only user working with the container.
Finally, I clicked Deploy the stack button to start the deployment.
Verifying the Deployment
I verified the deployment by opening the Containers page from the Portainer dashboard and clicking on the 2113-2113 link in the Published Ports column for the eventstoredb-eventstore.db-1 container to bring up the EventStoreDB dashboard.
Writing to the Database
I then created a NET Core console application to write some events to the database using the EventStoreDB documentation (https://developers.eventstore.com/clients/grpc/#connecting-to-eventstoredb).
using System.Text.Json;
using EventStore.Client;
var settings = EventStoreClientSettings.Create("esdb://powerspec.local.sleepingbearsystems.net:2113?tls=false");
var client = new EventStoreClient(settings);
var testEvent = new TestEvent(EntityId: Guid.NewGuid().ToString("N"), $"Test Message {DateTimeOffset.Now}");
var eventData = new EventData(Uuid.NewUuid(), nameof(TestEvent), JsonSerializer.SerializeToUtf8Bytes(testEvent));
var cancellationToken = new CancellationToken();
await client.AppendToStreamAsync(
"some-stream",
StreamState.Any,
new[] { eventData},
cancellationToken: cancellationToken);
public record TestEvent(string EntityId, string Message);
I ran the console program a few times to generate several events then verified the events were being written to the EventStoreDB database using the Stream Browser page.
Next Steps
With the EventStoreDB database deployed, I now need to move some containers from my old Docker server to the new Docker server to take advantage of the newer hardware.
TeamCity Build Agents
Postgres Server
pgAdmin Tool