Monday, June 11, 2018

Running RavenDB on Docker


We previously reviewed how to install or run standalone instances of RavenDB on our machines. Turns out that there's another interesting and fun way to run RavenDB: with Docker. Let's take a look.

Pre-requisites

The pre-requisite to running RavenDB on Docker is having docker installed. =)

Installing Docker

Let's skip Docker introductions. If you still don't have Docker installed on your machine, take a look at this page. Windows users should check this page out.

For Linux users, it shouldn't be more complicated than running 2 lines on the terminal.

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

Running RavenDB on Docker is super simple because the RavenDB team already provided a Docker image for us on 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

Running that command on my Fedora machine, I have:

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 automatically and 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

Since we mapped the internal and external container ports to 8080, I can access the instance by opening my browser and 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:

That's it! You now have a simple RavenDB Docker node running on your machine. No installation, no setup. Ideal solution for those who just a simple instance to start playing with or for developers who want a more portable setup.

Final Notes

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. No installation, no setup. Ideal solution for those who just a simple instance to start playing with. Notice how simple it was to run RavenDB smothly on a docker instance 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
Querying RavenDB MetadataPatching RavenDB Metadata

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

References

For further reference, please check these links:
https://github.com/ravendb/ravendb/tree/v4.0/docker
https://ravendb.net/docs/article-page/4.0/csharp/start/installation/setup-wizard
https://hub.docker.com/r/ravendb/ravendb/