Running Rust applications with Diesel on M1 Macs can be challenging due to missing necessary libraries. This repository offers a Docker solution to seamlessly run your Rust applications, ensuring compatibility and ease of setup.
- Docker installed on your M1 Mac.
-
Build the Docker Image:
Navigate to the directory containing the Dockerfile and run:
docker build -t rust_docker .This command builds the Docker image and tags it as
rust_docker. -
Configuration Changes:
Before running your application, make sure to adjust the connection URLs in your
config.yamlfile for the PostgreSQL and QDranT databases. Replacelocalhostwithhost.docker.internal. For example:database_url: "postgres://dboperator:operatorpass123@host.docker.internal:5432/postgres" qdrant_url: "http://host.docker.internal:6333"
This change allows the Docker container to connect to services running on your host machine.
-
Run the Docker Container:
In the root directory of your Rust project, execute:
docker run -it -p 3000:3000 -v $(pwd):/root/backend_infra rust_dockerThis command:
- Maps port
3000of the container to port3000on your host machine. - Mounts your current directory (your Rust project) to
/root/backend_infrain the Docker container. This ensures any changes you make to your local code will reflect in the container instantly. - Initiates the container with a Zsh shell, as configured in the Dockerfile.
- Maps port
-
Inside the Docker Container:
Once inside the container's shell:
- Navigate to
/root/backend_infra. - Run your Rust application as you normally would on a local setup.
- Navigate to
-
This setup uses Zsh for an enhanced shell experience, and the configuration has been copied into the container. Adjustments can be made by modifying the
.zshrcfile in this repository and rebuilding the Docker image. -
Always ensure that any services or databases running on your host are properly secured, especially when exposing ports or making connections.
Happy coding! 🚀