This guide assumes you already have Docker
Desktop installed.
To containerize our application, we define a
Dockerfile. This file contains a list of instructions to initialize the container, copy our local project files into it, install dependencies, and starts the application.
Dockerfile
Now that you have your docker image, let’s look at
.dockerignore which has the same syntax as .gitignore, here you need to specify the files/directories that must not go in any stage of the docker build. An example for a ignore file is
.dockerignore
We’ll now use
docker build to convert this Dockerfile into a Docker image, a self-contained template containing all the dependencies and configuration required to run the application.
The -t flag lets us specify a name for the image, and --pull tells Docker to automatically download the latest version of the base image (oven/bun). The initial build will take longer, as Docker will download all the base images and dependencies.
terminal
We’ve built a new Docker image. Now let’s use that image to spin up an actual, running container. We’ll use
docker run to start a new container using the bun-hello-world image. It will be run in detached mode (-d) and we’ll map the container’s port 3000 to our local machine’s port 3000 (-p 3000:3000).
The run command prints a string representing the container ID.
terminal
The container is now running in the background. Visit localhost:3000. You should see a
Hello, World! message.
To stop the container, we’ll use
docker stop <container-id>.
terminal
If you can’t find the container ID, you can use
docker ps to list all running containers.
terminal
That’s it! Refer to the Docker documentation for more advanced usage.