public class JibContainerBuilder extends Object
Example usage:
Jib.from(baseImage)
.addLayer(sourceFiles, extractionPath)
.setEntrypoint("myprogram", "--flag", "subcommand")
.setProgramArguments("hello", "world")
.addEnvironmentVariable("HOME", "/app")
.addExposedPort(Port.tcp(8080))
.addLabel("containerizer", "jib")
.containerize(...);
| Modifier and Type | Method and Description |
|---|---|
JibContainerBuilder |
addEnvironmentVariable(String name,
String value)
Sets a variable in the container environment.
|
JibContainerBuilder |
addExposedPort(Port port)
Adds a port to expose from the container.
|
JibContainerBuilder |
addLabel(String key,
String value)
Sets a label for the container.
|
JibContainerBuilder |
addLayer(LayerConfiguration layerConfiguration)
Adds a layer (defined by a
LayerConfiguration). |
JibContainerBuilder |
addLayer(List<Path> files,
AbsoluteUnixPath pathInContainer)
Adds a new layer to the container with
files as the source files and pathInContainer as the path to copy the source files to in the container file system. |
JibContainer |
containerize(Containerizer containerizer)
Builds the container.
|
JibContainerBuilder |
setCreationTime(Instant creationTime)
Sets the container image creation time.
|
JibContainerBuilder |
setEntrypoint(List<String> entrypoint)
Sets the container entrypoint.
|
JibContainerBuilder |
setEntrypoint(String... entrypoint)
Sets the container entrypoint.
|
JibContainerBuilder |
setEnvironment(Map<String,String> environmentMap)
Sets the container environment.
|
JibContainerBuilder |
setExposedPorts(List<Port> ports)
Sets the ports to expose from the container.
|
JibContainerBuilder |
setExposedPorts(Port... ports)
Sets the ports to expose from the container.
|
JibContainerBuilder |
setFormat(ImageFormat imageFormat)
Sets the format to build the container image as.
|
JibContainerBuilder |
setLabels(Map<String,String> labelMap)
Sets the labels for the container.
|
JibContainerBuilder |
setLayers(LayerConfiguration... layerConfigurations)
Sets the layers.
|
JibContainerBuilder |
setLayers(List<LayerConfiguration> layerConfigurations)
Sets the layers (defined by a list of
LayerConfigurations). |
JibContainerBuilder |
setProgramArguments(List<String> programArguments)
Sets the container entrypoint program arguments.
|
JibContainerBuilder |
setProgramArguments(String... programArguments)
Sets the container entrypoint program arguments.
|
JibContainerBuilder |
setUser(String user)
Sets the user and group to run the container as.
|
public JibContainerBuilder addLayer(List<Path> files, AbsoluteUnixPath pathInContainer) throws IOException
files as the source files and pathInContainer as the path to copy the source files to in the container file system.
Source files that are directories will be recursively copied. For example, if the source files are:
fileA
fileB
directory/
/path/in/container, then the new layer will have the
following entries for the container file system:
/path/in/container/fileA
/path/in/container/fileB
/path/in/container/directory/
/path/in/container/directory/... (all contents of directory/)
files - the source files to copy to a new layer in the containerpathInContainer - the path in the container file system corresponding to the sourceFileIOException - if an exception occurred when recursively listing any directoriespublic JibContainerBuilder setLayers(List<LayerConfiguration> layerConfigurations)
LayerConfigurations). This replaces any
previously-added layers.layerConfigurations - the list of LayerConfigurationspublic JibContainerBuilder setLayers(LayerConfiguration... layerConfigurations)
layerConfigurations - the LayerConfigurationspublic JibContainerBuilder addLayer(LayerConfiguration layerConfiguration)
LayerConfiguration).layerConfiguration - the LayerConfigurationpublic JibContainerBuilder setEntrypoint(@Nullable List<String> entrypoint)
setProgramArguments(java.util.List<java.lang.String>) sets additional tokens.
This is similar to ENTRYPOINT in Dockerfiles or command in the Kubernetes
Container spec.
entrypoint - a list of the entrypoint commandpublic JibContainerBuilder setEntrypoint(String... entrypoint)
entrypoint - the entrypoint commandfor more detailspublic JibContainerBuilder setProgramArguments(@Nullable List<String> programArguments)
This is similar to CMD in Dockerfiles or args in the Kubernetes
Container spec.
For example, if the entrypoint was myprogram --flag subcommand and program arguments
were hello world, then the command that run when the container starts is myprogram --flag subcommand hello world.
programArguments - a list of program argument tokenspublic JibContainerBuilder setProgramArguments(String... programArguments)
programArguments - program arguments tokensfor more detailspublic JibContainerBuilder setEnvironment(Map<String,String> environmentMap)
This is similar to ENV in Dockerfiles or env in the Kubernetes
Container spec.
environmentMap - a map of environment variable names to valuespublic JibContainerBuilder addEnvironmentVariable(String name, String value)
name - the environment variable namevalue - the environment variable valuefor more detailspublic JibContainerBuilder setExposedPorts(List<Port> ports)
Use Port.tcp(int) to expose a port for TCP traffic and Port.udp(int) to expose a port
for UDP traffic.
This is similar to EXPOSE in Dockerfiles or ports in the Kubernetes
Container spec.
ports - the list of ports to exposepublic JibContainerBuilder setExposedPorts(Port... ports)
ports - the ports to exposefor more detailspublic JibContainerBuilder addExposedPort(Port port)
port - the port to exposefor more detailspublic JibContainerBuilder setLabels(Map<String,String> labelMap)
This is similar to LABEL in Dockerfiles.
labelMap - a map of label keys to valuespublic JibContainerBuilder addLabel(String key, String value)
key - the label keyvalue - the label valuepublic JibContainerBuilder setFormat(ImageFormat imageFormat)
ImageFormat.Docker for Docker V2.2
or ImageFormat.OCI for OCI.imageFormat - the ImageFormatpublic JibContainerBuilder setCreationTime(Instant creationTime)
Instant.EPOCH.creationTime - the container image creation timepublic JibContainerBuilder setUser(@Nullable String user)
user can be a username or UID along
with an optional groupname or GID.
The following are valid formats for user
user
uid
user:group
uid:gid
uid:group
user:gid
user - the user to run the container aspublic JibContainer containerize(Containerizer containerizer) throws InterruptedException, ExecutionException, IOException, CacheDirectoryCreationException
containerizer - the Containerizer that configures how to containerizeCacheDirectoryCreationException - if a directory to be used for the cache could not be
createdExecutionException - if an exception occurred during executionInterruptedException - if the execution was interruptedIOException - if an I/O exception occursCopyright © 2018. All rights reserved.