Search code examples
dockermavendockerfilesha1integrity

Different SHA1 for copied files in my docker image (from Maven Build)


I'm currently building a Docker image for my projet using a Dockerfile. In it, I had to copy some file (binary machine learning model) loaded by a library in my project (I tried COPY and ADD commands) and it seems that the library are looking for the sha1 of the model file to verify its integrity.

However when I check the sha1 of this file in my running docker container, it's different from the sha1 of the original file (on the machine which build the image).

I checked for the other added files in my Docker image (scripts etc...) and all the sha1 are different.

We tried to build the image on different OS, tried to set system locales in the docker image (I thought something about encoding...) but nothing works. Is it a "normal" behavior for Docker?

Thanks

Edit : The Dockerfile is run by a the Spotify Maven Plugin (Java)


Solution

  • Finally I found out the problem. It was not docker nor Spotify Maven Plugin but the maven resources filtering when building the project. I don't know exactly what it's doing but my binary files are modified after this step. Added an exclude for these files and everything is good now.

    Code for reference:

    <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
            <execution>
                <id>prepare-dockerfile</id>
                <phase>validate</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/docker-ready</outputDirectory>
                    <resources>
                        <resource>
                            <directory>docker</directory>
                            <filtering>true</filtering>
                        </resource>
                    </resources>
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>p12</nonFilteredFileExtension>
                        <nonFilteredFileExtension>crt</nonFilteredFileExtension>
                        <nonFilteredFileExtension>pem</nonFilteredFileExtension>
                        <nonFilteredFileExtension>bin</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </execution>
        </executions>
    </plugin>