convex-backend
convex-backend copied to clipboard
Added support for docker-compose
- Added Docker file to build and run the convex-backend
- Added docker-compose file to start convex-backend with a single command line
- Added package-lock.json into the .gitignore file in demo project
- Changed convex-backend URL in the .env file to point to the right port
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
This seems reasonable!
I think we don't want to maintain the docker-compose just yet (eg the build process could change and it could go out of date), but we can probably accept this and put it in a subdirectory with obvious indication that it's community-supported.
Thanks for writing it up!
- Added Docker file to build and run the convex-backend
- Added docker-compose file to start convex-backend with a single command line
- Added package-lock.json into the .gitignore file in demo project
- Changed convex-backend URL in the .env file to point to the right port
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Hi @Olacdy, I'm trying to self-host convex using your Dockerfile, can you tell me what port 3211 is for?
https://github.com/search?q=repo%3Aget-convex%2Fconvex-backend%203211&type=code
It's where the http actions port binds. Equivalent of the .convex.site https://docs.convex.dev/functions/http-actions
I simplified and fixed the Dockerfile and tested it that it works:
# Stage 1: Build
FROM rust:latest AS build
# Install dependencies
RUN apt-get update && apt-get install -y curl && \
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y git build-essential clang libclang-dev nodejs
# Install Just (for build scripts)
RUN cargo install just
# Clone the Convex backend repository
RUN git clone https://github.com/get-convex/convex-backend.git /convex
WORKDIR /convex
# Install npm dependencies in the scripts folder
RUN npm install --prefix scripts
# Install Rush dependencies
RUN just rush install
# Build the convex-local-backend binary
RUN cargo build --release -p local_backend --bin convex-local-backend
# Stage 2: Final runtime
FROM ubuntu:22.04
# Install dependencies
RUN apt-get update && apt-get install -y libclang-dev libstdc++6 libc6
# Create a directory for the application
WORKDIR /usr/local/bin
# Copy the built binary from the build stage to the correct location
COPY --from=build /convex/target/release/convex-local-backend /usr/local/bin/convex-local-backend
# Set the backend as the executable
ENTRYPOINT ["./convex-local-backend"]
# Expose the required ports
EXPOSE 3210
EXPOSE 3211
Note that you probably want to preserve state across runs, so you must configure the db and local storage locations, and then mount them outside the container:
-d for detached
-ti for interactive
127.0.0.1 is localhost
./local is where the state will live on your (host) machine
/convex is where I am configuring the convex backend to store the state
/convex/db.sqlite3 is the location and name for the sqlite db file
/convex/storage is the location and name for the File Storage folder
for instance-secret and instance-name see SELFHOSTING
docker run -d \
-p 127.0.0.1:3210:3210 \
-p 127.0.0.1:3211:3211 \
-v ./local:/convex \
convex-backend /convex/db.sqlite3 \
--local-storage /convex/storage
--instance-secret 123456789 \
--instance-name my_fancy_backend
this will result in the Convex state being stored in the local directory where you run the above docker command.
i followed all the instruction but not it gave me
Program Files/Git/convex/db.sqlite3: Error code 14: Unable to open the database file
2024-12-19 15:46:38 2024-12-19T12:46:38.211539Z ERROR common::errors: Not reporting above error: SENTRY_DSN not set.
2024-12-19 15:46:38 Error: unable to open database file: C:/Program Files/Git/convex/db.sqlite3
in the log of the docker
@emmaling27 and me merged this with
6af68da428f0dca3e168e08f7aa77b25f4bba40c and 71a3ac3a9f062c7f95732b383bbf34a4a891503a We're planning on doing more work to help improve this over time - including making the flows smoother, instructions better, documentation more complete.
Appreciate the contribution!
if you're finding this task in the future - you can likely get some support in the Convex discord in the #open-source channel.
https://convex.dev/community