{"id":13546677,"url":"https://github.com/spotify/docker-maven-plugin","last_synced_at":"2025-09-28T19:31:27.210Z","repository":{"id":38419632,"uuid":"21144543","full_name":"spotify/docker-maven-plugin","owner":"spotify","description":"INACTIVE: A maven plugin for Docker","archived":true,"fork":false,"pushed_at":"2021-09-14T14:31:28.000Z","size":803,"stargazers_count":2665,"open_issues_count":21,"forks_count":572,"subscribers_count":145,"default_branch":"master","last_synced_at":"2025-01-16T04:11:00.837Z","etag":null,"topics":["docker","java","maven","maven-plugin"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spotify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-23T22:33:07.000Z","updated_at":"2025-01-06T20:11:59.000Z","dependencies_parsed_at":"2022-09-01T04:24:39.799Z","dependency_job_id":null,"html_url":"https://github.com/spotify/docker-maven-plugin","commit_stats":null,"previous_names":[],"tags_count":311,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fdocker-maven-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fdocker-maven-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fdocker-maven-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fdocker-maven-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spotify","download_url":"https://codeload.github.com/spotify/docker-maven-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234555772,"owners_count":18851841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","java","maven","maven-plugin"],"created_at":"2024-08-01T12:00:42.745Z","updated_at":"2025-09-28T19:31:21.854Z","avatar_url":"https://github.com/spotify.png","language":"Java","readme":"# docker-maven-plugin\n[![Build Status](https://travis-ci.com/spotify/docker-maven-plugin.svg?branch=master)](https://travis-ci.com/spotify/docker-maven-plugin)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.spotify/docker-maven-plugin/badge.svg?style=flat-square)](https://maven-badges.herokuapp.com/maven-central/com.spotify/docker-maven-plugin/)\n[![License](https://img.shields.io/github/license/spotify/dockerfile-maven.svg)](LICENSE)\n\n\nA Maven plugin for building and pushing Docker images.\n\n## Status: inactive\n\n**We recommend you use [dockerfile-maven][] instead.**\n\n### The future of docker-maven-plugin\n\nThis plugin was the initial Maven plugin used at Spotify for building Docker\nimages out of Java services. It was initially created in 2014 when we first\nbegan experimenting with Docker. This plugin is capable of generating a\n`Dockerfile` for you based on configuration in the pom.xml file for things like\nthe `FROM` image, resources to add with `ADD`/`COPY`, etc.\n\nOver time at Spotify we have realized that the simplest way to build a Docker\nimage from a Java project is to have the developer write the `Dockerfile`.  The\nbehavior of this plugin around generating Dockerfiles, copying your project\ndirectory to a \"staging\" directory to use as the Docker build context, etc.,\nultimately led to a lot of unnecessary confusion with our users that stemmed\nfrom introducing extra abstractions and a need for configuration on top of what\nDocker is providing.\n\nThis led to the creation of a second Maven plugin for building docker images,\n[dockerfile-maven][], which we think offers a simpler mental model of working\nwith Docker from Maven, for all of the reasons outlined in dockerfile-maven's\nREADME.\n\n\n[dockerfile-maven]: https://github.com/spotify/dockerfile-maven\n* [The future of docker-maven-plugin](#the-future-of-docker-maven-plugin)\n* [Purpose](#purpose)\n* [Setup](#setup)\n  * [Specify build info in the POM](#specify-build-info-in-the-pom)\n  * [Use a Dockerfile](#use-a-dockerfile)\n* [Usage](#usage)\n  * [Bind Docker commands to Maven phases](#bind-docker-commands-to-maven-phases)\n  * [Using with Private Registries](#using-with-private-registries)\n  * [Authentication](#authentication)\n    * [Using encrypted passwords for authentication](#using-encrypted-passwords-for-authentication)\n* [Testing](#testing)\n* [Releasing](#releasing)\n* [Known Issues](#known-issues)\n\n\n## Purpose\n\nYou can use this plugin to create a Docker image with artifacts built from your Maven project. For\nexample, the build process for a Java service can output a Docker image that runs the service.\n\n## Setup\n\nYou can specify the base image, entry point, cmd, maintainer and files you want to add to your\nimage directly in the pom, without needing a separate `Dockerfile`.\nIf you need `VOLUME` command(or any other not supported dockerfile command), then you will need\nto create a `Dockerfile` and use the `dockerDirectory` element.\n\nBy default the plugin will try to connect to docker on localhost:2375. Set the DOCKER_HOST \nenvironment variable to connect elsewhere.\n\n    DOCKER_HOST=tcp://\u003chost\u003e:2375\n\nOther docker-standard environment variables are honored too such as TLS and certificates.\n\n### Specify build info in the POM\n\nThis example creates a new image named `example`, copies the project's jar file into the image,\nand sets an entrypoint which runs the jar. Change `VERSION GOES HERE` to the latest tagged version.\n\n    \u003cbuild\u003e\n      \u003cplugins\u003e\n        ...\n        \u003cplugin\u003e\n          \u003cgroupId\u003ecom.spotify\u003c/groupId\u003e\n          \u003cartifactId\u003edocker-maven-plugin\u003c/artifactId\u003e\n          \u003cversion\u003eVERSION GOES HERE\u003c/version\u003e\n          \u003cconfiguration\u003e\n            \u003cimageName\u003eexample\u003c/imageName\u003e\n            \u003cbaseImage\u003ejava\u003c/baseImage\u003e\n            \u003centryPoint\u003e[\"java\", \"-jar\", \"/${project.build.finalName}.jar\"]\u003c/entryPoint\u003e\n            \u003c!-- copy the service's jar file from target into the root directory of the image --\u003e \n            \u003cresources\u003e\n               \u003cresource\u003e\n                 \u003ctargetPath\u003e/\u003c/targetPath\u003e\n                 \u003cdirectory\u003e${project.build.directory}\u003c/directory\u003e\n                 \u003cinclude\u003e${project.build.finalName}.jar\u003c/include\u003e\n               \u003c/resource\u003e\n            \u003c/resources\u003e\n          \u003c/configuration\u003e\n        \u003c/plugin\u003e\n        ...\n      \u003c/plugins\u003e\n    \u003c/build\u003e\n\n### Use a Dockerfile\n\nTo use a `Dockerfile`, you must specify the `dockerDirectory` element. If specified, the \n`baseImage`, `maintainer`, `cmd` and `entryPoint` elements will be ignored. The contents of the\n`dockerDirectory` will be copied into `${project.build.directory}/docker`. Use the `resources`\nelement to copy additional files, such as the service's jar file.\n\n    \u003cbuild\u003e\n      \u003cplugins\u003e\n        ...\n        \u003cplugin\u003e\n          \u003cgroupId\u003ecom.spotify\u003c/groupId\u003e\n          \u003cartifactId\u003edocker-maven-plugin\u003c/artifactId\u003e\n          \u003cversion\u003eVERSION GOES HERE\u003c/version\u003e\n          \u003cconfiguration\u003e\n            \u003cimageName\u003eexample\u003c/imageName\u003e\n            \u003cdockerDirectory\u003edocker\u003c/dockerDirectory\u003e\n            \u003cresources\u003e\n               \u003cresource\u003e\n                 \u003ctargetPath\u003e/\u003c/targetPath\u003e\n                 \u003cdirectory\u003e${project.build.directory}\u003c/directory\u003e\n                 \u003cinclude\u003e${project.build.finalName}.jar\u003c/include\u003e\n               \u003c/resource\u003e\n            \u003c/resources\u003e\n          \u003c/configuration\u003e\n        \u003c/plugin\u003e\n        ...\n      \u003c/plugins\u003e\n    \u003c/build\u003e\n\n## Usage\n\nYou can build an image with the above configurations by running this command.\n\n    mvn clean package docker:build\n\nTo push the image you just built to the registry, specify the `pushImage` flag.\n\n    mvn clean package docker:build -DpushImage\n\nTo push only specific tags of the image to the registry, specify the `pushImageTag` flag.\n\n    mvn clean package docker:build -DpushImageTag\n\nIn order for this to succeed, at least one imageTag must be present in the config, multiple tags can be used.\n\n    \u003cbuild\u003e\n      \u003cplugins\u003e\n        ...\n        \u003cplugin\u003e\n          \u003cconfiguration\u003e\n            ...\n            \u003cimageTags\u003e\n               \u003cimageTag\u003e${project.version}\u003c/imageTag\u003e\n               \u003cimageTag\u003elatest\u003c/imageTag\u003e\n            \u003c/imageTags\u003e\n          \u003c/configuration\u003e\n        \u003c/plugin\u003e\n        ...\n      \u003c/plugins\u003e\n    \u003c/build\u003e\n\nOptionally, you can force docker to overwrite your image tags on each new build:\n\n    \u003cbuild\u003e\n      \u003cplugins\u003e\n        ...\n        \u003cplugin\u003e\n          \u003cconfiguration\u003e\n            ...\n            \u003c!-- optionally overwrite tags every time image is built with docker:build --\u003e\n            \u003cforceTags\u003etrue\u003c/forceTags\u003e\n            \u003cimageTags\u003e\n               ...\n            \u003c/imageTags\u003e\n          \u003c/configuration\u003e\n        \u003c/plugin\u003e\n        ...\n      \u003c/plugins\u003e\n    \u003c/build\u003e\n\nTags-to-be-pushed can also be specified directly on the command line with\n\n    mvn ... docker:build -DpushImageTag -DdockerImageTags=latest,another-tag\n\n### Bind Docker commands to Maven phases\n\nYou can also bind the build, tag \u0026 push goals to the Maven phases, so the container will be built, tagged and pushed \nwhen you run just `mvn deploy`. If you have a multi-module project where a sub-module builds an image, you\nwill need to do this binding so the image gets built when maven is run from the parent project. \n\n    \u003cplugin\u003e\n      \u003cgroupId\u003ecom.spotify\u003c/groupId\u003e\n      \u003cartifactId\u003edocker-maven-plugin\u003c/artifactId\u003e\n      \u003cversion\u003eVERSION GOES HERE\u003c/version\u003e\n      \u003cexecutions\u003e\n        \u003cexecution\u003e\n          \u003cid\u003ebuild-image\u003c/id\u003e\n          \u003cphase\u003epackage\u003c/phase\u003e\n          \u003cgoals\u003e\n            \u003cgoal\u003ebuild\u003c/goal\u003e\n          \u003c/goals\u003e\n        \u003c/execution\u003e\n        \u003cexecution\u003e\n          \u003cid\u003etag-image\u003c/id\u003e\n          \u003cphase\u003epackage\u003c/phase\u003e\n          \u003cgoals\u003e\n            \u003cgoal\u003etag\u003c/goal\u003e\n          \u003c/goals\u003e\n          \u003cconfiguration\u003e\n            \u003cimage\u003emy-image:${project.version}\u003c/image\u003e\n            \u003cnewName\u003eregistry.example.com/my-image:${project.version}\u003c/newName\u003e\n          \u003c/configuration\u003e\n        \u003c/execution\u003e\n        \u003cexecution\u003e\n          \u003cid\u003epush-image\u003c/id\u003e\n          \u003cphase\u003edeploy\u003c/phase\u003e\n          \u003cgoals\u003e\n            \u003cgoal\u003epush\u003c/goal\u003e\n          \u003c/goals\u003e\n          \u003cconfiguration\u003e\n            \u003cimageName\u003eregistry.example.com/my-image:${project.version}\u003c/imageName\u003e\n          \u003c/configuration\u003e\n        \u003c/execution\u003e        \n      \u003c/executions\u003e\n    \u003c/plugin\u003e\n\nYou can skip Docker goals bound to Maven phases with:\n\n* `-DskipDockerBuild` to skip image build\n* `-DskipDockerTag` to skip image tag\n* `-DskipDockerPush` to skip image push\n* `-DskipDocker` to skip any Docker goals\n\nTo remove the image named `foobar` run the following command:\n\n    mvn docker:removeImage -DimageName=foobar\n\nFor a complete list of configuration options run:\n`mvn com.spotify:docker-maven-plugin:\u003cversion\u003e:help -Ddetail=true`\n\n### Using with Private Registries\n\nTo push an image to a private registry, Docker requires that the image tag\nbeing pushed is prefixed with the hostname and port of the registry. For\nexample to push `my-image` to `registry.example.com`, the image needs to be\ntagged as `registry.example.com/my-image`.\n\nThe simplest way to do this with docker-maven-plugin is to put the registry\nname in the `\u003cimageName\u003e` field, for example\n\n```xml\n\u003cplugin\u003e\n  \u003cgroupId\u003ecom.spotify\u003c/groupId\u003e\n  \u003cartifactId\u003edocker-maven-plugin\u003c/artifactId\u003e\n  \u003cconfiguration\u003e\n    \u003cimageName\u003eregistry.example.com/my-image\u003c/imageName\u003e\n    ...\n```\n\nThen when pushing the image with either `docker:build -DpushImage` or\n`docker:push`, the docker daemon will push to `registry.example.com`.\n\nAlternatively, if you wish to use a short name in `docker:build` you can use\n`docker:tag -DpushImage` to tag the just-built image with the full registry\nhostname and push it. It's important to use the `pushImage` flag as using\n`docker:push` independently will attempt to push the original image.\n\nFor example:\n\n```xml\n\u003cplugin\u003e\n  \u003cgroupId\u003ecom.spotify\u003c/groupId\u003e\n  \u003cartifactId\u003edocker-maven-plugin\u003c/artifactId\u003e\n  \u003cconfiguration\u003e\n    \u003cimageName\u003emy-image\u003c/imageName\u003e\n    ...\n  \u003c/configuration\u003e\n  \u003cexecutions\u003e\n    \u003cexecution\u003e\n      \u003cid\u003ebuild-image\u003c/id\u003e\n      \u003cphase\u003epackage\u003c/phase\u003e\n      \u003cgoals\u003e\n        \u003cgoal\u003ebuild\u003c/goal\u003e\n      \u003c/goals\u003e\n    \u003c/execution\u003e\n    \u003cexecution\u003e\n      \u003cid\u003etag-image\u003c/id\u003e\n      \u003cphase\u003epackage\u003c/phase\u003e\n      \u003cgoals\u003e\n        \u003cgoal\u003etag\u003c/goal\u003e\n      \u003c/goals\u003e\n      \u003cconfiguration\u003e\n        \u003cimage\u003emy-image\u003c/image\u003e\n        \u003cnewName\u003eregistry.example.com/my-image\u003c/newName\u003e\n      \u003c/configuration\u003e\n    \u003c/execution\u003e\n  \u003c/executions\u003e\n\u003c/plugin\u003e\n```\n\n### Authentication\n\nSince version 1.0.0, the docker-maven-plugin will automatically use any\nauthentication present in the docker-cli configuration file at `~/.dockercfg`\nor `~/.docker/config.json`, without the need to configure anything (in earlier\nversions of the plugin this behavior had to be enabled with\n`\u003cuseConfigFile\u003etrue\u003c/useConfigFile\u003e`, but now it is always active).\n\nAdditionally the plugin will enable support for Google Container Registry if it\nis able to successfully load [Google's \"Application Default Credentials\"][ADC].\nThe plugin will also load Google credentials from the file pointed to by the\nenvironment variable `DOCKER_GOOGLE_CREDENTIALS` if it is defined. Since GCR\nauthentication requires retrieving short-lived access codes for the given\ncredentials, support for this registry is baked into the underlying\ndocker-client rather than having to first populate the docker config file\nbefore running the plugin.\n\n[ADC]: https://developers.google.com/identity/protocols/application-default-credentials\n\nLastly, authentication credentials can be explicitly configured in your pom.xml\nand in your Maven installation's `settings.xml` file as part of the\n`\u003cservers\u003e\u003c/servers\u003e` block.\n\n    \u003cservers\u003e\n      \u003cserver\u003e\n        \u003cid\u003edocker-hub\u003c/id\u003e\n        \u003cusername\u003efoo\u003c/username\u003e\n        \u003cpassword\u003esecret-password\u003c/password\u003e\n        \u003cconfiguration\u003e\n          \u003cemail\u003efoo@foo.bar\u003c/email\u003e\n        \u003c/configuration\u003e\n      \u003c/server\u003e\n    \u003c/servers\u003e\n\nNow use the server id in your project `pom.xml`.\n\n    \u003cplugin\u003e\n      \u003cplugin\u003e\n        \u003cgroupId\u003ecom.spotify\u003c/groupId\u003e\n        \u003cartifactId\u003edocker-maven-plugin\u003c/artifactId\u003e\n        \u003cversion\u003eVERSION GOES HERE\u003c/version\u003e\n        \u003cconfiguration\u003e\n          [...]\n          \u003cserverId\u003edocker-hub\u003c/serverId\u003e\n          \u003cregistryUrl\u003ehttps://index.docker.io/v1/\u003c/registryUrl\u003e\n        \u003c/configuration\u003e\n      \u003c/plugin\u003e\n    \u003c/plugins\u003e\n\nThe plugin gives priority to any credentials in the docker-cli config file\nbefore explicitly configured credentials.\n\n#### Using encrypted passwords for authentication\n\nCredentials can be encrypted using [Maven's built in encryption function.](https://maven.apache.org/guides/mini/guide-encryption.html)\nOnly passwords enclosed in curly braces will be considered as encrypted.\n\n    \u003cservers\u003e\n      \u003cserver\u003e\n        \u003cid\u003edocker-hub\u003c/id\u003e\n        \u003cusername\u003efoo\u003c/username\u003e\n        \u003cpassword\u003e{gc4QPLrlgPwHZjAhPw8JPuGzaPitzuyjeBojwCz88j4=}\u003c/password\u003e\n      \u003c/server\u003e\n    \u003c/servers\u003e\n\n## Testing\n\nMake sure Docker daemon is running and that you can do `docker ps`. Then run `mvn clean test`.\n\n## Releasing\n\nCommits to the master branch will trigger our continuous integration agent to build the jar and\nrelease by uploading to Sonatype. If you are a project maintainer with the necessary credentials,\nyou can also build and release locally by running the below.\n\n```sh\nmvn release:clean\nmvn release:prepare\nmvn release:perform\n```\n\n## Known Issues\n\n### Exception caught: system properties: docker has type STRING rather than OBJECT\n\nBecause the plugin uses Maven properties named like\n`docker.build.defaultProfile`, if you declare any other Maven property with the\nname `docker` you will get a rather strange-looking error from Maven:\n\n```\n[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.0.21:build (default) on project \u003c....\u003e: \nException caught: system properties: docker has type STRING rather than OBJECT\n```\n\nTo fix this, rename the `docker` property in your pom.xml.\n\n### InternalServerErrorException: HTTP 500 Internal Server Error\n\nProblem: when building the Docker image, Maven outputs an exception with a\nstacktrace like:\n\n\u003e Caused by: com.spotify.docker.client.shaded.javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error\n\ndocker-maven-plugin communicates with your local Docker daemon using the HTTP\nRemote API and any unexpected errors that the daemon encounters will be\nreported as `500 Internal Server Error`.\n\nCheck the Docker daemon log (typically at `/var/log/docker.log` or\n`/var/log/upstart/docker.log`) for more details.\n\n#### Invalid repository name ... only [a-z0-9-\\_.] are allowed\n\nOne common cause of `500 Internal Server Error` is attempting to build an image\nwith a repository name containing uppercase characters, such as if the\n`\u003cimageName\u003e` in the plugin's configuration refers to `${project.version}` when\nthe Maven project version is ending in `SNAPSHOT`.\n\nConsider putting the project version in an image tag (instead of repository\nname) with the `\u003cdockerImageTags\u003e` configuration option instead.\n","funding_links":[],"categories":["HarmonyOS","Java","maven-plugin","容器化工具"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspotify%2Fdocker-maven-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspotify%2Fdocker-maven-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspotify%2Fdocker-maven-plugin/lists"}