Docker allows developers to package applications and dependencies into standard, shippable units, great for easy deployments across platforms and constantly changing needs. Crate is available as a Docker image and is a perfect data store for Docker based applications.
if you don't have Docker setup yet, find instructions for all platforms here.
Kitematic is Docker's visual interface for creating Docker instances on Windows and Mac. Crate can be found in the list of default images in Kitematic.
Click the Create button and Kitematic will download the image file from Docker hub and by default set port allocation between Docker and the host machine automatically.
To override settings for a Docker instance, click the Settings tab. For example to manually allocate ports and set a shared volume between Docker and the local machine, make the following changes:
To use the command line to create Crate instances, first fetch the latest Crate image.
docker pull crate
Specify versions of the image by applying the
docker run -P -d crate docker run -P -d crate docker run -d -p 4200:4200 -p 4300:4300 crate
In this example we create three instances. The first two let Docker set the port allocation between Docker and the host automatically and one sets ports manually. These three instances will discover each other automatically.
Then visit your Docker IP address on port 4200, e.g. http://DOCKER_IP:4200/admin
The above is a simple example, to make better use of Crate with Docker, we should set some other parameters.
docker run -d -p 4200:4200 -p 4300:4300 -v <data-dir>:/data crate crate -Des.config=/path/to/crate.yml -Des.cluster.name=cluster
This starts a Crate Docker instance that maps the data storage path to a location shared between the Docker container and the host system (The value of
<data-dir>). This helps data remain consistent and persistent as container instances come and go on a local machine.
We also set a path to the Crate config file for fine grained settings changes, and give the cluster a name.
Docker's Compose tool allows developers to configure complex Docker-based applications that can then be started with one
docker-compose up command.
Read about Docker Compose specifics here. In this example we will start a node.js container that connects to a two instance Crate cluster.
crate: image: crate ports: - "4200:4200" - "4300:4300" volumes: - /mnt/data/crate:/data environment: CRATE_HEAP_SIZE: 16g command: crate -Des.config=/path/to/crate.yml -Des.cluster.name=cluster crate2: image: crate volumes: - /mnt/data/crate:/data node: build: . ports: - "8000:8000" links: - crate
Here we create one Crate instance with the ports manually allocated, a shared file system volume, an environment variable set for the heap size and override the default Crate command to give the cluster a name and a config file. We then create another instance that joins the other in a cluster and a node.js instance that links to a Crate instance.
Crate works with any Docker instances created with the Machine tool. Combined with Docker's cluster tool, Swarm, Crate becomes a powerful companion to Docker. Setting up Crate as part of a Docker Swarm is a little more complicated, but we have a guide to get you started.