Loading...

How to use docker build

Jonas Scholz
2 min read 22. Okt. 2024

The docker build command is used to build Docker images from a Dockerfile. Let's cover the essential usage and most important options.

Basic Usage

The basic syntax is:

docker build [OPTIONS] PATH | URL | -

This tells Docker to build an image using the Dockerfile in the specified PATH or URL. The . at the end means "current directory".

Most Important Options

Here are the most commonly used options:

-t, --tag

Tag your image (give it a name):

docker build -t myapp:latest .

-f, --file

Specify a different Dockerfile name:

docker build -f custom.Dockerfile .

--no-cache

Force a fresh build without using cached layers:

docker build --no-cache .

--build-arg

Pass variables to the build process:

docker build --build-arg VERSION=1.0 .

--platform

Build for specific platforms:

docker build --platform linux/amd64,linux/arm64 .

--pull

Always pull the latest base images:

docker build --pull .

Common Use Cases

  1. Basic build with tag:
docker build -t myapp:1.0 .
  1. Build with multiple tags:
docker build -t myapp:latest -t myapp:1.0 .
  1. Build with build arguments:
docker build --build-arg ENV=production -t myapp:prod .

Conclusion

While docker build has many options, these are the ones you'll use most often. They cover the essential needs for building Docker images: naming your images, specifying build variables, and controlling the build cache.

Welcome to the container cloud

Sliplane makes it simple to deploy containers in the cloud and scale up as you grow. Try it now and get started in minutes!