I have a very strange issue with my Rust program that uses the rocket-rs library.
The issue I am facing is that when I try and build my program in a Docker container using a Dockerfile
I created, some parts of the config I set out in the rocket.toml
file is not applied. More specifically, I have set the log level
option to critical
in the config file and that is working but the address
option I have set in the config file is not applied.
What is wierd is that I can build and all the options are applied on my local machine properly but not in the container.
Output when I build and run the program on my machine (no docker):
Configured for release.
>> address: 0.0.0.0
>> port: 8000
>> workers: 12
>> ident: Rocket
>> keep-alive: 5s
>> limits: bytes = 8KiB, data-form = 2MiB, file = 1MiB, form = 32KiB, json = 1MiB, msgpack = 1MiB, string = 8KiB
>> tls: disabled
>> temp dir: C:\Users\Nlanson\AppData\Local\Temp\
>> log level: critical
>> cli colors: true
>> shutdown: ctrlc = true, force = true, grace = 2s, mercy = 3s
Output when I build and run the program in a docker container:
Configured for release.
>> address: 127.0.0.1 //This is what I do not want
>> port: 8000
>> workers: 2
>> ident: Rocket
>> keep-alive: 5s
>> limits: bytes = 8KiB, data-form = 2MiB, file = 1MiB, form = 32KiB, json = 1MiB, msgpack = 1MiB, string = 8KiB
>> tls: disabled
>> temp dir: /tmp
>> log level: critical
>> cli colors: true
>> shutdown: ctrlc = true, force = true, signals = [SIGTERM], grace = 2s, mercy = 3s
Here is the Dockerfile I am using:
FROM rust as builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM rust as runtime
WORKDIR /app
COPY --from=builder /app/target/release/server .
COPY --from=builder /app/database.db .
EXPOSE 8000
CMD ["./server"]
and my rocket config file:
[global]
#address is not applied
address = "0.0.0.0"
#log level is applied
log_level = "critical"
I have tried a few things to trouble shoot this issue:
- Run the container with
docker run -it <container name> bash
and check that all the required files including the config file is copied into the container - Build the program in the container through bash using different options.
Please let me know if I am missing any details.
Thanks in advance