github.com/szyn/goreleaser@v0.76.1-0.20180517112710-333da09a1297/www/content/docker.md (about)

     1  ---
     2  title: Docker
     3  series: customization
     4  hideFromIndex: true
     5  weight: 140
     6  ---
     7  
     8  Since [v0.31.0](https://github.com/goreleaser/goreleaser/releases/tag/v0.31.0),
     9  GoReleaser supports building and pushing Docker images.
    10  
    11  ## How it works
    12  
    13  You can declare multiple Docker images. They will be matched against
    14  the binaries generated by your `builds` section.
    15  
    16  If you have only one `build` setup,
    17  the configuration is as easy as adding the
    18  name of your image to your `.goreleaser.yml` file:
    19  
    20  ```yaml
    21  dockers:
    22    - image: user/repo
    23  ```
    24  
    25  You also need to create a `Dockerfile` in your project's root folder:
    26  
    27  ```dockerfile
    28  FROM scratch
    29  COPY mybin /
    30  ENTRYPOINT ["/mybin"]
    31  ```
    32  
    33  This configuration will build and push a Docker image named `user/repo:tagname`.
    34  
    35  ## Customization
    36  
    37  Of course, you can customize a lot of things:
    38  
    39  ```yaml
    40  # .goreleaser.yml
    41  dockers:
    42    # You can have multiple Docker images.
    43    -
    44      # GOOS of the built binary that should be used.
    45      goos: linux
    46      # GOARCH of the built binary that should be used.
    47      goarch: amd64
    48      # GOARM of the built binary that should be used.
    49      goarm: ''
    50      # Name of the built binary that should be used.
    51      binary: mybinary
    52      # Docker image name.
    53      image: myuser/myimage
    54      # Skips the docker push. Could be useful if you also do draft releases.
    55      # Defaults to false.
    56      skip_push: false
    57      # Path to the Dockerfile (from the project root).
    58      dockerfile: Dockerfile
    59      # Template of the docker tag. Defaults to `{{ .Version }}`.
    60      # Other allowed fields are:
    61      # - `.Commint`
    62      # - `.Tag`
    63      # - `.Major`
    64      # - `.Minor`
    65      # - `.Patch`
    66      # - `.Env.VARIABLE_NAME`
    67      tag_templates:
    68      - "{{ .Tag }}"
    69      - "{{ .Tag }}-{{ .Env.GO_VERSION }}"
    70      - "v{{ .Major }}"
    71      - latest
    72      # If your Dockerfile copies files other than the binary itself,
    73      # you should list them here as well.
    74      extra_files:
    75      - config.yml
    76  ```
    77  
    78  These settings should allow you to generate multiple Docker images,
    79  for example, using multiple `FROM` statements,
    80  as well as generate one image for each binary in your project.
    81  
    82  ## Passing environment variables to tag_template
    83  
    84  You can do that by using `{{ .Env.VARIABLE_NAME }}` in the template, for
    85  example:
    86  
    87  ```yaml
    88  dockers:
    89    -
    90      tag_template: "{{ .Tag }}-{{ .Env.GOVERSION_NR }}"
    91  ```
    92  
    93  Then you can run:
    94  
    95  ```console
    96  GOVERSION_NR=$(go version | awk '{print $3}') goreleaser
    97  ```
    98  
    99  ## Keeping docker images updated for current major
   100  
   101  Some users might want to when version to push docker tags `:v1`, `:v1.6`,
   102  `:v1.6.4` and `:latest` when `v1.6.4` (for example) is built. That can be
   103  accomplished by using multiple `tag_templates`:
   104  
   105  ```yaml
   106  # .goreleaser.yml
   107  dockers:
   108    -
   109      binary: mybinary
   110      image: myuser/myimage
   111      tag_templates:
   112      - "{{ .Tag }}"
   113      - "v{{ .Major }}"
   114      - "v{{ .Major }}.{{ .Minor }}"
   115      - latest
   116  ```
   117  
   118  This will build and publish the following images:
   119  
   120  * myuser/myimage:v1.6.4
   121  * myuser/myimage:v1
   122  * myuser/myimage:v1.6
   123  * myuser/myimage:latest
   124  
   125  With these settings you can hopefully push several different docker images
   126  with multiple tags.