<p></p>
<p>Not certain why you need all these layers. It doesn't matter if you throw away the temporary image. Otherwise you could combine the RUN lines.</p>
<p>My build was only interested in the artifact, so I had another entry to create later a versioned image only containing osm2pgsql.<br>
For inspiration, here my file:</p>
<pre><code>FROM osmtools/builder as builder

WORKDIR /
ARG DEBIAN_FRONTEND=noninteractive
ARG CLICOLOR_FORCE=1
ENV TZ=Europe/Berlin

ARG VERSION=master

RUN git clone --depth 1 --branch $VERSION git://github.com/openstreetmap/osm2pgsql.git \
    && mkdir osm2pgsql/build && cd osm2pgsql/build && cmake -D WITH_LUAJIT=ON -D CMAKE_BUILD_TYPE=MinSizeRel .. && make -j$(nproc)

FROM scratch
WORKDIR /
COPY --from=builder /osm2pgsql/build/osm2pgsql /build/
</code></pre>
<p>I call it like:</p>
<pre><code>OSM2PGSQL_VERSION=1.4.1
docker build --pull -t osmtools/osm2pgsql:"$OSM2PGSQL_VERSION" --build-arg VERSION="$OSM2PGSQL_VERSION" osm2pgsql
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/osm2pgsql/pull/1427#issuecomment-797344202">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AA6353SR63XC7VOXWEMXJWLTDHKB3ANCNFSM4ZB2J25A">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AA6353VQEGPNADFGR2TTYPLTDHKB3A5CNFSM4ZB2J25KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOF6DIDSQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/osm2pgsql/pull/1427#issuecomment-797344202",
"url": "https://github.com/openstreetmap/osm2pgsql/pull/1427#issuecomment-797344202",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>