You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d80ff17
Browse filesBrowse the repository at this point in the historyBrowse files
Jib is a Maven plugin for building Docker and OCI images for your Java applications.
11
+
Jib builds Docker and OCI images for your Java applications and is available as plugins for [Maven](jib-maven-plugin) and [Gradle](jib-gradle-plugin).
12
+
13
+
[Maven](https://maven.apache.org/): See documentation for [jib-maven-plugin](jib-maven-plugin).
14
+
[Gradle](https://gradle.org/): See documentation for [jib-gradle-plugin](jib-gradle-plugin).
12
15
13
16
## Goals
14
17
@@ -18,252 +21,22 @@ Jib is a Maven plugin for building Docker and OCI images for your Java applicati
18
21
19
22
***Native** - Reduce your CLI dependencies. Build your Docker image from within Maven <!--or Gradle--> and push to any registry of your choice. *No more writing Dockerfiles and calling docker build/push.*
20
23
21
-
## Upcoming Features
22
-
23
-
These features are not currently supported but will be added in later releases.
24
-
25
-
* Support for WAR format
26
-
27
24
## Quickstart
28
25
29
-
### Setup
30
-
31
-
In your Maven Java project, add the plugin to your `pom.xml`:
32
-
33
-
```xml
34
-
<plugin>
35
-
<groupId>com.google.cloud.tools</groupId>
36
-
<artifactId>jib-maven-plugin</artifactId>
37
-
<version>0.1.6</version>
38
-
<configuration>
39
-
<registry>myregistry</registry>
40
-
<repository>myapp</repository>
41
-
</configuration>
42
-
</plugin>
43
-
```
44
-
45
-
### Configuration
46
-
47
-
Configure the plugin by changing `registry` and `repository` to be the registry and repository to push the built image to.
48
-
49
-
#### Using [Google Container Registry (GCR)](https://cloud.google.com/container-registry/)...
50
-
51
-
*Make sure you have the [`docker-credential-gcr` command line tool](https://cloud.google.com/container-registry/docs/advanced-authentication#docker_credential_helper). Jib automatically uses `docker-credential-gcr` for obtaining credentials. See [Authentication Methods](#authentication-methods) for other ways of authenticating.*
52
-
53
-
For example, to build the image `gcr.io/my-gcp-project/my-app`, the configuration would be:
54
-
55
-
```xml
56
-
<configuration>
57
-
<registry>gcr.io</registry>
58
-
<repository>my-gcp-project/my-app</repository>
59
-
</configuration>
60
-
```
61
-
62
-
#### Using [Amazon Elastic Container Registry (ECR)](https://aws.amazon.com/ecr/)...
63
-
64
-
*Make sure you have the [`docker-credential-ecr-login` command line tool](https://github.com/awslabs/amazon-ecr-credential-helper). Jib automatically uses `docker-credential-ecr-login` for obtaining credentials. See [Authentication Methods](#authentication-methods) for other ways of authenticating.*
65
-
66
-
For example, to build the image `aws_account_id.dkr.ecr.region.amazonaws.com/my-app`, the configuration would be:
#### Using [Docker Hub Registry](https://hub.docker.com/)...
26
+
### Maven
76
27
77
-
*Make sure you have a [docker-credential-helper](https://github.com/docker/docker-credential-helpers#available-programs) set up. For example, on macOS, the credential helper would be `docker-credential-osxkeychain`. See [Authentication Methods](#authentication-methods) for other ways of authenticating.*
78
-
79
-
For example, to build the image `my-docker-id/my-app`, the configuration would be:
#### *TODO: Add more examples for common registries.*
90
-
91
-
### Build Your Image
92
-
93
-
Build your container image with:
94
-
95
-
```shell
96
-
mvn compile jib:build
97
-
```
98
-
99
-
Subsequent builds are much faster than the initial build.
100
-
101
-
If you want to clear Jib's build cache and force it to re-pull the base image and re-build the application layers, run:
102
-
103
-
```shell
104
-
mvn clean compile jib:build
105
-
```
106
-
107
-
*Having trouble? Let us know by [submitting an issue](/../../issues/new), contacting us on [Gitter](https://gitter.im/google/jib), or posting to the [Jib users forum](https://groups.google.com/forum/#!forum/jib-users).*
108
-
109
-
### Bind to a lifecycle
110
-
111
-
You can also bind `jib:build` to a Maven lifecycle, such as `package`, by adding the following execution to your `jib-maven-plugin` definition:
112
-
113
-
```xml
114
-
<plugin>
115
-
<groupId>com.google.com.tools</groupId>
116
-
<artifactId>jib-maven-plugin</artifactId>
117
-
...
118
-
<executions>
119
-
<execution>
120
-
<phase>package</phase>
121
-
<goals>
122
-
<goal>build</goal>
123
-
</goals>
124
-
</execution>
125
-
</executions>
126
-
</plugin>
127
-
```
128
-
129
-
Then, you can build your container image by running:
130
-
131
-
```shell
132
-
mvn package
133
-
```
28
+
See documentation for using [jib-maven-plugin](jib-maven-plugin#quickstart).
134
29
135
-
### Export to a Docker context
30
+
### Gradle
136
31
137
-
Jib can also export to a Docker context so that you can build with Docker, if needed:
138
-
139
-
```shell
140
-
mvn compile jib:dockercontext
141
-
```
142
-
143
-
The Docker context will be created at `target/jib-dockercontext` by default. You can change this directory with the `targetDir` configuration option or the `jib.dockerDir` parameter:
Extended configuration options provide additional options for customizing the image build.
158
-
159
-
Field | Default | Description
160
-
--- | --- | ---
161
-
`from`|[`gcr.io/distroless/java`](https://github.com/GoogleCloudPlatform/distroless)|The base image to build your application on top of.
162
-
`registry`|*Required*|The registry server to push the built image to.
163
-
`repository`|*Required*|The image name/repository of the built image.
164
-
`tag`|`latest`|The image tag of the built image (the part after the colon).
165
-
`credHelpers`|*Required*|Suffixes for credential helpers (following `docker-credential-`)
166
-
`jvmFlags`|*None*|Additional flags to pass into the JVM when running your application.
167
-
`mainClass`|Uses `mainClass` from `maven-jar-plugin`|The main class to launch the application from.
168
-
`enableReproducibleBuilds`|`true`|Building with the same application contents always generates the same image. Note that this does *not* preserve file timestamps and ownership.
169
-
`imageFormat`|`Docker`|Use `OCI` to build an [OCI container image](https://www.opencontainers.org/).
170
-
`useOnlyProjectCache`|`false`|If set to true, Jib does not share a cache between different Maven projects.
171
-
172
-
### Example
173
-
174
-
In this configuration, the image is:
175
-
* Built from a base of `openjdk:alpine` (pulled from Docker Hub)
176
-
* Pushed to `localhost:5000/my-image:built-with-jib`
Pushing/pulling from private registries require authorization credentials. These can be [retrieved using Docker credential helpers](#using-docker-credential-helpers) or [defined in your Maven settings](#using-maven-settings). If you do not define credentials explicitly, Jib will try to [use credentials defined in your Docker config](/../../issues/101) or infer common credential helpers.
204
-
205
-
#### Using Docker Credential Helpers
206
-
207
-
Docker credential helpers are CLI tools that handle authentication with various registries.
208
-
209
-
Some common credential helpers include:
210
-
211
-
* Google Container Registry: [`docker-credential-gcr`](https://cloud.google.com/container-registry/docs/advanced-authentication#docker_credential_helper)
Configure credential helpers to use by specifying them in the `credHelpers` configuration.
218
-
219
-
*Example configuration:*
220
-
```xml
221
-
<configuration>
222
-
...
223
-
<credHelpers>
224
-
<credHelper>osxkeychain</credHelper>
225
-
</credHelpers>
226
-
...
227
-
</configuration>
228
-
```
229
-
230
-
#### Using Maven Settings
231
-
232
-
Registry credentials can be added to your [Maven settings](https://maven.apache.org/settings.html). These credentials will be used if credentials could not be found in any specified Docker credential helpers.
233
-
234
-
If you're considering putting credentials in Maven, we highly *recommend* using [maven password encryption](https://maven.apache.org/guides/mini/guide-encryption.html).
235
-
236
-
*Example `settings.xml`:*
237
-
```xml
238
-
<settings>
239
-
...
240
-
<servers>
241
-
...
242
-
<server>
243
-
<id>MY_REGISTRY</id>
244
-
<username>MY_USERNAME</username>
245
-
<password>{MY_SECRET}</password>
246
-
</server>
247
-
</servers>
248
-
</settings>
249
-
```
250
-
251
-
* The `id` field should be the registry server these credentials are for.
252
-
* We *do not* recommend putting your raw password in `settings.xml`.
32
+
See documentation for using [jib-gradle-plugin](jib-gradle-plugin#quickstart).
253
33
254
34
## How Jib Works
255
35
256
36
Whereas traditionally a Java application is built as a single image layer with the application JAR, Jib's build strategy separates the Java application into multiple layers for more granular incremental builds. When you change your code, only your changes are rebuilt, not your entire application. These layers, by default, are layered on top of a [distroless](https://github.com/GoogleCloudPlatform/distroless) base image.
257
37
258
38
See also [rules_docker](https://github.com/bazelbuild/rules_docker) for a similar existing container image build tool for the [Bazel build system](https://github.com/bazelbuild/bazel).
259
39
260
-
## Known Limitations
261
-
262
-
These limitations will be fixed in later releases.
263
-
264
-
* Cannot build directly to a Docker daemon.
265
-
* Pushing to Azure Container Registry is not currently supported.
266
-
267
40
## Frequently Asked Questions (FAQ)
268
41
269
42
If a question you have is not answered below, please [submit an issue](/../../issues/new).
@@ -274,7 +47,15 @@ See [rules_docker](https://github.com/bazelbuild/rules_docker) for a similar exi
274
47
275
48
### What image format does Jib use?
276
49
277
-
Jib currently builds into the [Docker V2.2](https://docs.docker.com/registry/spec/manifest-v2-2/) image format or [OCI image format](https://github.com/opencontainers/image-spec). See [Extended Usage](#extended-usage) for the `imageFormat` configuration.
50
+
Jib currently builds into the [Docker V2.2](https://docs.docker.com/registry/spec/manifest-v2-2/) image format or [OCI image format](https://github.com/opencontainers/image-spec).
51
+
52
+
#### Maven
53
+
54
+
See [Extended Usage](jib-maven-plugin#extended-usage) for the `imageFormat` configuration.
55
+
56
+
#### Gradle
57
+
58
+
See [Extended Usage](jib-gradle-plugin#extended-usage) for the `format` configuration.
278
59
279
60
### Can I define a custom entrypoint?
280
61
@@ -306,21 +87,39 @@ Jib packages your Java application into the following paths on the image:
306
87
307
88
Running commands like `apt-get` slows down the container build process. We **do not recommend or support** running commands as part of the build.
308
89
309
-
However, if you need to run commands, you can build a custom base image. You can then use this custom base image in the `jib-maven-plugin` by adding the following configuration:
90
+
However, if you need to run commands, you can build a custom image and configure Jib to use it as the base image.
In [`jib-maven-plugin`](jib-maven-plugin), you can then use this custom base image by adding the following configuration:
310
99
311
100
```xml
312
101
<configuration>
313
102
<from>custom-base-image</from>
314
103
</configuration>
315
104
```
316
105
106
+
#### Gradle
107
+
108
+
In [`jib-gradle-plugin`](jib-gradle-plugin), you can then use this custom base image by adding the following configuration:
109
+
110
+
```groovy
111
+
jib.from.image = 'custom-base-image'
112
+
```
113
+
</p>
114
+
</details>
115
+
317
116
### Can I ADD a custom directory to the image?
318
117
319
118
We currently do not support adding a custom directory to the image. If your application needs to use custom files, place them into your application's resources directory (`src/main/resources` by default). These resource files will be available on the classpath.
320
119
321
120
### Can I build to a local Docker daemon?
322
121
323
-
We currently do not support building to a local Docker daemon. However, this feature is in the pipeline and will be added in the future.
122
+
We currently do not support building to a local Docker daemon. However, [this feature is in the pipeline and will be added in the future](/../../issues/48).
324
123
325
124
You can still [`docker pull`](https://docs.docker.com/engine/reference/commandline/pull/) the image built with `jib-maven-plugin` to have it available in your local Docker daemon.
326
125
@@ -366,6 +165,8 @@ See more at [Using Google Container Registry (GCR) with Minikube](https://ryanes
366
165
367
166
### How can I tag my image with a timestamp?
368
167
168
+
#### Maven
169
+
369
170
To tag the image with a simple timestamp, add the following to your `pom.xml`:
370
171
371
172
```xml
@@ -384,6 +185,14 @@ Then in the `jib-maven-plugin` configuration, set the `tag` to:
384
185
385
186
You can then use the same timestamp to reference the image in other plugins.
386
187
188
+
#### Gradle
189
+
190
+
To tag the image with a timestamp, simply set the timestamp as the tag for `to.image` in your `jib` configuration. For example:
Copy file name to clipboardExpand all lines: jib-maven-plugin/README.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,8 @@
6
6
7
7
Jib is a [Maven](https://maven.apache.org/) plugin for building Docker and OCI images for your Java applications.
8
8
9
-
For information about the project, see the [Jib project README](/../../).
10
-
For the Gradle plugin, see the [jib-gradle-plugin project](/../../tree/master/jib-gradle-plugin).
9
+
For information about the project, see the [Jib project README](..).
10
+
For the Gradle plugin, see the [jib-gradle-plugin project](../jib-gradle-plugin).
11
11
12
12
## Upcoming Features
13
13
@@ -222,6 +222,8 @@ Configure credential helpers to use by specifying them in the `credHelpers` conf
222
222
223
223
Registry credentials can be added to your [Maven settings](https://maven.apache.org/settings.html). These credentials will be used if credentials could not be found in any specified Docker credential helpers.
224
224
225
+
If you're considering putting credentials in Maven, we highly *recommend* using [maven password encryption](https://maven.apache.org/guides/mini/guide-encryption.html).
226
+
225
227
*Example `settings.xml`:*
226
228
```xml
227
229
<settings>
@@ -231,7 +233,7 @@ Registry credentials can be added to your [Maven settings](https://maven.apache.
0 commit comments