Monday, June 11, 2018

Running RavenDB on Docker

Developers are now able to run RavenDB on Docker. On this post, let's review how that works.

RavenDB 4.0 brought us ability to be run Docker containers. On this post, let's review in detail how that works and test it on a Linux box. But before, let's jump directly to a quick review on how to get it installed on our Linux boxes.

Installing Docker

Installing Docker on Ubuntu/Fedora workstations shouldn't be more complicated than running these 2 lines below on the terminal. Windows users please check this page out.

Installing on Ubuntu

# In Ubuntu and Debian-based distros
sudo apt-get install docker

Installing on RH-based distros (Fedora, Cent, etc)

# In RH based distros (Fedora, Cent, etc)
sudo dnf install docker

Running a Docker RavenDB Instance

Now the fun part! Running RavenDB on Docker is super simple. The RavenDB team on Docker Hub already provided a Docker image that can be downloaded directly from Docker Hub. Assuming that your machine has internet connection, we just need to run the command below on a terminal:
sudo docker run -p 8080:8080 ravendb/ravendb
For example, when I ran that command on my Fedora machine, I get:

Reviewing the Previous Command

Let's review what happened on the above screenshot:
  • Docker detected that I didn't have the image available locally so it pulls the binary directly from Docker Hub
  • After completed the download, the RavenDB initialization starts
  • We then see RavenDB initialization messages such as Tcp listening on 172.17.0.2:38888. This is Raven's telling us its default TCP port. Note that we didn't map that port out of the container, so it will not be available
  • Once the "Running non-interactive" message is outputted, the instance is ready to be tested.

Accessing the Instance

With the RavenDB docker instance running, let's see how to access it. Since we mapped the internal and external container ports to 8080, I can access my instance by navigating to https://localhost:8080/ The "Welcome message" shows up as for a regular installation. It's because that docker instance is treated as a brand new installation.

Configuring RavenDb's Docker Instance

Now, let's proceed with the configuration of our RavenDB instance. I have outlined everything here in case you want to review it. TLDR, click on "Unsecure" to start initialize a development version:

Then Raven Studio is open for us. This is what we need to start interacting with the database:

Post-Installation

That's it! You now have a simple RavenDB Docker node running on your machine. Please note that In Docker, we can also use port mapping with the -p flag, To do so, we'll need to check the box "Customize external IP and Ports" and supply the external IP address as well as the exposed ports. So I then can create container using:
$ sudo docker run -t -p 38889:38888 -p 443:8080 ravendb/ravendb
I recommend exploring other parameters when running the RavenDB docker container. More information is available on this page.

Conclusion

In this post I demoed how easy it is to have RavenDB running on Docker on your machine. Ideal solution for those who just a simple instance to start playing with. Also notice how simple it was to run RavenDB on my Fedora Linux workstation.

Try it out. This is an excellent way to test RavenDB and exercise your Docker abilities.

See Also

A simple introduction to RavenDB
Installing and Running RavenDB on Windows and Linux
Creating a Ubuntu Desktop instance on Azure
Thank you, Fedora
Querying RavenDB Metadata
Patching RavenDB Metadata
Raven Studio

For more RavenDB posts on this blog, please click here.

References


RavenDB team on Docker Hub
DockerHub - RavenDB 4.0
RavenDB - Installation: Setup Wizard Walkthrough