github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/www/docs/customization/docker.md (about)

     1  ---
     2  title: Docker
     3  ---
     4  
     5  Since [v0.31.0](https://github.com/goreleaser/goreleaser/releases/tag/v0.31.0),
     6  GoReleaser supports building and pushing Docker images.
     7  
     8  ## How it works
     9  
    10  You can declare multiple Docker images. They will be matched against
    11  the binaries generated by your `builds` section and packages generated
    12  by your `nfpms` section.
    13  
    14  If you have only one `build` setup,
    15  the configuration is as easy as adding the
    16  name of your image to your `.goreleaser.yml` file:
    17  
    18  ```yaml
    19  dockers:
    20    - image_templates:
    21      - user/repo
    22  ```
    23  
    24  !!! tip
    25      The `image_templates` attribute supports templating. Learn more about the [name template engine](/customization/templates/).
    26  
    27  You also need to create a `Dockerfile` in your project's root folder:
    28  
    29  ```dockerfile
    30  FROM scratch
    31  ENTRYPOINT ["/mybin"]
    32  COPY mybin /
    33  ```
    34  
    35  This configuration will build and push a Docker image named `user/repo:tagname`.
    36  
    37  !!! warning
    38      Note that we are not building any go files in the Docker
    39      build phase, we are merely copying the binary to a `scratch` image and
    40      setting up the `entrypoint`.
    41  
    42  ## Customization
    43  
    44  Of course, you can customize a lot of things:
    45  
    46  ```yaml
    47  # .goreleaser.yml
    48  dockers:
    49    # You can have multiple Docker images.
    50    -
    51      # ID of the image, needed if you want to filter by it later on (e.g. on custom publishers).
    52      id: myimg
    53  
    54      # GOOS of the built binaries/packages that should be used.
    55      goos: linux
    56  
    57      # GOARCH of the built binaries/packages that should be used.
    58      goarch: amd64
    59  
    60      # GOARM of the built binaries/packages that should be used.
    61      goarm: ''
    62  
    63      # IDs to filter the binaries/packages.
    64      ids:
    65      - mybuild
    66      - mynfpm
    67  
    68      # Templates of the Docker image names.
    69      image_templates:
    70      - "myuser/myimage:latest"
    71      - "myuser/myimage:{{ .Tag }}"
    72      - "myuser/myimage:{{ .Tag }}-{{ .Env.GO_VERSION }}"
    73      - "myuser/myimage:v{{ .Major }}"
    74      - "gcr.io/myuser/myimage:latest"
    75  
    76      # Skips the docker push.
    77      # Could be useful if you also do draft releases.
    78      #
    79      # If set to auto, the release will not be pushed to the Docker repository
    80      #  in case there is an indicator of a prerelease in the tag, e.g. v1.0.0-rc1.
    81      #
    82      # Defaults to false.
    83      skip_push: false
    84  
    85      # Path to the Dockerfile (from the project root).
    86      dockerfile: Dockerfile
    87  
    88      # Set the "backend" for the Docker pipe.
    89      # Valid options are: docker, buildx, podman, buildpacks
    90      # podman is a GoReleaser Pro feature and is only available on Linux.
    91      # Defaults to docker.
    92      use: docker
    93  
    94      # Template of the docker build flags.
    95      build_flag_templates:
    96      - "--pull"
    97      - "--label=org.opencontainers.image.created={{.Date}}"
    98      - "--label=org.opencontainers.image.title={{.ProjectName}}"
    99      - "--label=org.opencontainers.image.revision={{.FullCommit}}"
   100      - "--label=org.opencontainers.image.version={{.Version}}"
   101      - "--build-arg=FOO={{.Env.Bar}}"
   102      - "--platform=linux/arm64"
   103  
   104      # Extra flags to be passed down to the push command.
   105      # Defaults to empty.
   106      push_flags:
   107      - --tls-verify=false
   108  
   109      # If your Dockerfile copies files other than binaries and packages,
   110      # you should list them here as well.
   111      # Note that GoReleaser will create the same structure inside a temporary
   112      # folder, so if you add `foo/bar.json` here, on your Dockerfile you can
   113      # `COPY foo/bar.json /whatever.json`.
   114      # Also note that the paths here are relative to the folder in which
   115      # GoReleaser is being run (usually the repository root folder).
   116      # This field does not support wildcards, you can add an entire folder here
   117      # and use wildcards when you `COPY`/`ADD` in your Dockerfile.
   118      extra_files:
   119      - config.yml
   120  ```
   121  
   122  !!! tip
   123      Learn more about the [name template engine](/customization/templates/).
   124  
   125  !!! tip
   126      You can also create multi-platform images using the [docker_manifests](/customization/docker_manifest/) config.
   127  
   128  These settings should allow you to generate multiple Docker images,
   129  for example, using multiple `FROM` statements,
   130  as well as generate one image for each binary in your project or one image with multiple binaries, as well as
   131  install the generated packages instead of copying the binary and configs manually.
   132  
   133  ## Generic Image Names
   134  
   135  Some users might want to keep their image name as generic as possible.
   136  That can be accomplished simply by adding template language in the definition:
   137  
   138  ```yaml
   139  # .goreleaser.yml
   140  project: foo
   141  dockers:
   142    -
   143      image_templates:
   144      - "myuser/{{.ProjectName}}"
   145  ```
   146  
   147  This will build and publish the following images:
   148  
   149  - `myuser/foo`
   150  
   151  !!! tip
   152      Learn more about the [name template engine](/customization/templates/).
   153  
   154  ## Keeping docker images updated for current major
   155  
   156  Some users might want to push docker tags `:v1`, `:v1.6`,
   157  `:v1.6.4` and `:latest` when `v1.6.4` (for example) is built. That can be
   158  accomplished by using multiple `image_templates`:
   159  
   160  ```yaml
   161  # .goreleaser.yml
   162  dockers:
   163    -
   164      image_templates:
   165      - "myuser/myimage:{{ .Tag }}"
   166      - "myuser/myimage:v{{ .Major }}"
   167      - "myuser/myimage:v{{ .Major }}.{{ .Minor }}"
   168      - "myuser/myimage:latest"
   169  ```
   170  
   171  This will build and publish the following images:
   172  
   173  - `myuser/myimage:v1.6.4`
   174  - `myuser/myimage:v1`
   175  - `myuser/myimage:v1.6`
   176  - `myuser/myimage:latest`
   177  
   178  With these settings you can hopefully push several Docker images
   179  with multiple tags.
   180  
   181  !!! tip
   182      Learn more about the [name template engine](/customization/templates/).
   183  
   184  ## Publishing to multiple docker registries
   185  
   186  Some users might want to push images to multiple docker registries. That can be
   187  accomplished by using multiple `image_templates`:
   188  
   189  ```yaml
   190  # .goreleaser.yml
   191  dockers:
   192    -
   193      image_templates:
   194      - "docker.io/myuser/myimage:{{ .Tag }}"
   195      - "docker.io/myuser/myimage:latest"
   196      - "gcr.io/myuser/myimage:{{ .Tag }}"
   197      - "gcr.io/myuser/myimage:latest"
   198  ```
   199  
   200  This will build and publish the following images to `docker.io` and `gcr.io`:
   201  
   202  - `myuser/myimage:v1.6.4`
   203  - `myuser/myimage:latest`
   204  - `gcr.io/myuser/myimage:v1.6.4`
   205  - `gcr.io/myuser/myimage:latest`
   206  
   207  ## Applying Docker build flags
   208  
   209  Build flags can be applied using `build_flag_templates`.
   210  The flags must be valid Docker build flags.
   211  
   212  ```yaml
   213  # .goreleaser.yml
   214  dockers:
   215    -
   216      image_templates:
   217      - "myuser/myimage"
   218      build_flag_templates:
   219      - "--pull"
   220      - "--label=org.opencontainers.image.created={{.Date}}"
   221      - "--label=org.opencontainers.image.title={{.ProjectName}}"
   222      - "--label=org.opencontainers.image.revision={{.FullCommit}}"
   223      - "--label=org.opencontainers.image.version={{.Version}}"
   224  ```
   225  
   226  This will execute the following command:
   227  
   228  ```bash
   229  docker build -t myuser/myimage . \
   230    --pull \
   231    --label=org.opencontainers.image.created=2020-01-19T15:58:07Z \
   232    --label=org.opencontainers.image.title=mybinary \
   233    --label=org.opencontainers.image.revision=da39a3ee5e6b4b0d3255bfef95601890afd80709 \
   234    --label=org.opencontainers.image.version=1.6.4
   235  ```
   236  
   237  !!! tip
   238      Learn more about the [name template engine](/customization/templates/).
   239  
   240  ## Podman
   241  
   242  !!! success "GoReleaser Pro"
   243      The podman backend is a [GoReleaser Pro feature](/pro/).
   244  
   245  You can use [`podman`](https://podman.io) instead of `docker` by setting `use` to `podman` on your config:
   246  
   247  ```yaml
   248  # .goreleaser.yml
   249  dockers:
   250    -
   251      image_templates:
   252      - "myuser/myimage"
   253      use: podman
   254  ```
   255  
   256  Note that GoReleaser will not install Podman for you, nor change any of its configuration.
   257  
   258  ## Buildpacks
   259  
   260  You can use [`buildpacks`](https://buildpacks.io) instead of `docker` by setting `use` to `buildpacks` on your config:
   261  
   262  ```yaml
   263  # .goreleaser.yml
   264  dockers:
   265    -
   266      image_templates:
   267      - "myuser/myimage"
   268      use: buildpacks
   269  ```
   270  
   271  Also, you can use a custom buildpack on `build_flag_templates` if you want.
   272  By default, `gcr.io/buildpacks/builder:v1` will be used.
   273  
   274  ```yaml
   275  # .goreleaser.yml
   276  dockers:
   277    -
   278      image_templates:
   279      - "myuser/myimage"
   280      use: buildpacks
   281      build_flag_templates:
   282      - "--builder=heroku/buildpacks:20"
   283  ```