Skip to content

Implement docker:commit #1869

@OndraZizka

Description

@OndraZizka

I have a scenario where the image is created by:

  1. Running a database image
  2. Running a Flyway image, creating a schema in the DB
  3. Committing the image using docker commit,
    which captures the state of the container into an image.

AFAICT, docker-maven-plugin doesn't have any way to do that.

So I resorted to the following. (Please disregard the granit-latest as a version, I am restricted in naming by Gitlab.)

<groupId>org.codehaus.mojo</groupId><artifactId>exec-maven-plugin</artifactId> ...
                        <configuration>
                            <executable>docker</executable>
... 

                            <execution><id>granit-container-commit</id><goals><goal>exec</goal></goals><phase>integration-test</phase>
                                <configuration>
                                    <arguments>
                                        <argument>commit</argument><argument>--message</argument><argument>CRDB with schemas applied by Flyway.</argument>
                                        <argument>cockroach-1</argument><argument>${nx.gitlabImagesRepo}:granit-${project.version}</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution><id>granit-image-tag</id><goals><goal>exec</goal></goals><phase>integration-test</phase>
                                <configuration>
                                    <arguments>
                                        <argument>tag</argument>
                                        <argument>${nx.gitlabImagesRepo}:granit-${project.version}</argument>
                                        <argument>${nx.gitlabImagesRepo}:granit-latest</argument>
                                    </arguments>
                                </configuration>
                            </execution>

Which is a bit cumbersome and could be replaced by a few lines of DMP.

                                <image>
                                    <name>${nx.gitlabImagesRepo}</name>
                                    <run>
                                        ...
                                        <commit>
                                              <tags>granit-latest</tags>
                                              <message>...</message>
                                              ...
                                        </commit>
                                    </run>
                                </image>
...
<execution><id>granit-image-commit</id><phase>post-integration-test</phase><goals><goal>commit</goal></goals></execution>

The docker:commit would look for <image>s with <run> which have <commit>, and commit the container right after stopping it.

Other things that Docker can apply when performing a commit can be taken from the <build> section: CMD|ENTRYPOINT|ENV|EXPOSE|LABEL|ONBUILD|USER|VOLUME|WORKDIR (in which case it would have to have <skip>true<skip> to avoid actually building it?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions