Docker Compose
Mini-tutorial on setting up crossbar with docker-compose
Operating Crossbar with Docker Compose
Prerequisites
Before deploying the Docker container, ensure you have the following:
Docker and Docker Compose installed on your machine.
Step 1: Set Up Your Project Directory
Create a Project Directory: Create a directory for your project. This directory will contain all the necessary files for your Docker container deployment.
Step 2: Create the docker-compose.yml
File
Create a
docker-compose.yml
File: In your project directory, create a file nameddocker-compose.yml
. This file will define the Docker services and environment variables.
Step 3: Create the .env
File
Create a
.env
File: In the same directory, create a.env
file to store your environment variables. This file will override the default values if specified.
Step 4: Build and Run the Docker Container
Build and Run the Docker Container: Navigate to your project directory and run the following command to start your Docker container:
This command will start the container in detached mode. The -d
flag stands for "detached," meaning the container runs in the background.
Step 5: Verify the Deployment
Verify the Deployment: Once the container is running, you can verify that the service is up and running by accessing it at
http://localhost:8080
. You can also check the status of the container by running:
This command will show the status of the running services.
Step 6: Stopping and Restarting the Docker Container
Stop the Docker Container: To stop the container, run:
This command will stop and remove the containers defined in your docker-compose.yml
file.
Restart the Docker Container: To restart the container, run:
Additional Tips
Logs: To view the logs of the running container, use the following command:
Updating Environment Variables: If you need to update the environment variables, edit the
.env
file and restart the container:
Scaling Services: If you need to scale your service, you can do so by specifying the number of instances:
This command will run three instances of my_service
.
Testing it out:
Try the deployment out by navigating to (can take a few seconds the first run): http://localhost:8080/updates/evm/1115/4f0e020e3d6f65cf21adb7766d065f787293154964be259dddb56e848ff838a0
The equivalent result should look something like the output from the public node: https://crossbar.switchboard.xyz/updates/evm/1115/4f0e020e3d6f65cf21adb7766d065f787293154964be259dddb56e848ff838a0
Last updated