Content microservice image

The second microservice we will use is the content microservice that we created in Chapter 9, Simple REST Definition and Request Routing with Frameworks. We also prepared this service for use with the PostgreSQL database. We borrowed the dockerignore file from the previous example and adapted the Dockerfile file for this microservice. Look at the following code:

FROM rust:nightly

RUN USER=root cargo new --bin content-microservice
WORKDIR /content-microservice
COPY ./Cargo.toml ./Cargo.toml
RUN cargo build

RUN rm src/*.rs
COPY ./src ./src
RUN rm ./target/debug/deps/content_microservice*
RUN cargo build

CMD ["./target/debug/content-microservice"]
EXPOSE 8000

As you can see, this Dockerfile is the same as the Dockerfile of the previous image, but it has one difference: it doesn't copy any configuration files. We'll are using the Rocket framework, but we will set all the parameters using the environment variables in the Docker Compose file.

You can build this image with the following command to check how it works:

 docker build -t content-microservice:latest .

But it's not necessary to build this image, because we won't start containers manually—we will use Docker Compose. Let's pack an email microservice to an image too.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.96.105