diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b8cae6c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..323f804 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# Build +FROM rust:alpine as builder +ARG TARGET_ARCH=x86_64-unknown-linux-musl + +RUN apk add --no-cache musl-dev alpine-sdk +WORKDIR /usr/src/mavlink2rest +COPY . . + +RUN rustup target add ${TARGET_ARCH} + +RUN cargo build --release --target=${TARGET_ARCH} + + +# Runtime environment +FROM alpine +WORKDIR /root/ + +ARG TARGET_ARCH=x86_64-unknown-linux-musl + +COPY --from=builder /usr/src/mavlink2rest/target/${TARGET_ARCH}/release/mavlink2rest ./mavlink2rest + +ENV MAVLINK_SRC="udpin:0.0.0.0:14550" +ENV SERVER_PORT="0.0.0.0:8088" +ENV EXTRA_ARGS="" + +RUN chmod +x mavlink2rest + +ENTRYPOINT ./mavlink2rest -c ${MAVLINK_SRC} -s ${SERVER_PORT} ${EXTRA_ARGS} diff --git a/README.md b/README.md index 1d09ea3..8fceee6 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,33 @@ OPTIONS: --system-id Sets system ID for this service. [default: 255] ``` +# Using Docker with mavlink2rest + +You can also use the `mavlink2rest` with docker, the following command will start the service with the default settings: +```sh +docker run --rm --init -p 8088:8088 -p 14550:14550/udp --name mavlink2rest mavlink/mavlink2rest +``` + +The Dockerfile defines several environment variables that you can override at runtime: + +MAVLINK_SRC: The MAVLink source connection string. Default is udpin:127.0.0.1:14550. +SERVER_PORT: The IP and port for the REST server. Default is 0.0.0.0:8088. +EXTRA_ARGS: Any additional command line arguments you want to pass to mavlink2rest. +To customize these settings, use the -e flag with docker run: + +```sh +docker run --rm --init\ + -p 8088:8088 \ + -p 14551:14551/udp \ + -e MAVLINK_SRC="udpin:0.0.0.0:14551" \ + -e SERVER_PORT="0.0.0.0:8088" \ + --name mavlink2rest mavlink/mavlink2rest +``` + +to build the docker image locally, you can use the following command: +```sh +docker build --build-arg TARGET_ARCH=x86_64-unknown-linux-musl -t mavlink/mavlink2rest . +``` ## Endpoints