Skip to main content

Publish a Docker image

This tutorial will guide you through creating a Docker image of your echo server and publishing it on Docker Hub.

Install Docker

Docker can be installed from https://docs.docker.com/engine/install/. Once it is installed, you should be able to run

docker

and see its help output.

oyster-cvm also has a helpful command you can use to verify that Docker has been installed:

oyster-cvm doctor --docker

Login to your Docker account

Run

sudo docker login

and follow the instructions to login to your Docker Hub account, creating one if necessary.

Create a Dockerfile

Run

cat > Dockerfile <<EOF
FROM rust:alpine AS builder
WORKDIR /usr/src/app
COPY . .
RUN apk add musl-dev
RUN cargo build --release

FROM alpine
COPY --from=builder /usr/src/app/target/release/echo-server /usr/local/bin/echo-server
CMD ["echo-server"]
EOF

to create a Dockerfile. This helps build and package the echo server into a Docker image.

Build and publish the Docker image

Run

# Replace <username> with your Docker username
sudo docker build -t <username>/echo-server:latest --push .

to build the Docker image and push it to Docker Hub.

tip

In a production application, you would want the Docker image to be built reproducibly to let users trace the Docker image back to the code it was built from.

Test the Docker image locally

Run

sudo docker run --rm --init -p 8080:8080 <username>/echo-server

to run the Docker image locally for testing.

You should be able to run nc 127.0.0.1 8080 in a new terminal now to test the echo server locally.

Now that you have a Docker image, you are ready to deploy it on Oyster.