This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/docs/guides/1205-container-images.md
user.email d20ffbe8be website: hardcode version banner for 0.1 docs
O.1 docs is deprecated. Let's inform user to switch the the latest version

Signed-off-by: user.email <jf@dagger.io>
2022-04-13 15:58:51 +02:00

2.3 KiB

slug displayed_sidebar
/1205/container-images 0.2

Building container images

You can use Dagger to build container images, either by executing a Dockerfile, or specifying the build steps natively in CUE. Which method to choose depends on the requirements of your project. You can mix and match builds from both methods in the same plan.

Executing a Dockerfile

Dagger can natively load and execute Dockerfiles. This is recommended in cases where compatibility with existing Dockerfiles is more important than fully leveraging the power of CUE.

Here's a simple example of a Dockerfile build:


Specifying a build in CUE

You can specify your container build natively in CUE, using the official Docker package: universe.dagger.io/docker. This is recommended when you don't need to worry about Dockerfile compatibility, and want to take advantage of the full power of CUE and the Dagger APIs.

Native CUE builds have the same backend as Dockerfile builds, so all the same features are available. Since CUE is a more powerful language than the Dockerfile syntax, every Dockerfile can be ported to an equivalent CUE configuration, but the opposite is not true. The following example produces the same image as above.


Because this build configuration is pure CUE, it can leverage the full power of Dagger's composition model.

Automation

Building images in CUE gives you greater flexibility. For example, you can automate building multiple versions of an image, and deploy, all in Dagger:


Now you can deploy all versions:

dagger do versions

Or just build a specific version, without pushing:

dagger do versions 8.0 build

Multi-stage build

Another common pattern is multi-stage builds. This allows you to have heavier build images during the build process, and copy the built artifacts into a cleaner and lighter image to run in production.