# Building Docker image on a machine and deploying on another invalidates precompile cache

**URL:** https://discourse.julialang.org/t/building-docker-image-on-a-machine-and-deploying-on-another-invalidates-precompile-cache/123086
**Category:** Tooling
**Created:** [November 26, 2024, 9:41am UTC](https://discourse.julialang.org/t/building-docker-image-on-a-machine-and-deploying-on-another-invalidates-precompile-cache/123086 "2024-11-26T09:41:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Pere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pere/32/214250_2.png) [@Pere](https://discourse.julialang.org/u/Pere)
#### Post date: [November 26, 2024, 9:41am UTC](https://discourse.julialang.org/t/building-docker-image-on-a-machine-and-deploying-on-another-invalidates-precompile-cache/123086/1 "2024-11-26T09:41:14Z")

</div>

I’m building a Docker image with a precompile statement in its Dockerfile to make startup faster. If I deploy the image on the same machine where it was built, it starts up very quick. However, If I deploy to a different machine, the precompilation runs again whenever the container is started.

I suppose the precompile cache is invalidated due to the machine change, even if they share the same architecture. Does anyone know how to solve this?

Here’s an example of the type of app I’m trying to deploy

> **[GitHub - BuiltWithGenie/IrisClustering: Genie demo app - Iris Clustering](https://github.com/BuiltWithGenie/IrisClustering)**
>
> Genie demo app - Iris Clustering

and its Dockerfile

```julia

FROM julia:latest
RUN apt-get update && apt-get install -y vim
RUN useradd --create-home --shell /bin/bash genie
RUN mkdir /home/genie/app
COPY . /home/genie/app
WORKDIR /home/genie/app
RUN chown -R genie:genie /home/
USER genie
EXPOSE 8000
EXPOSE 80
ENV JULIA_DEPOT_PATH "/home/genie/.julia"
ENV JULIA_REVISE = "off"
ENV GENIE_ENV "prod"
ENV GENIE_HOST "0.0.0.0"
ENV PORT "8000"
ENV WSPORT "8000"
ENV EARLYBIND "true"
RUN julia -e "using Pkg; Pkg.activate(\".\"); Pkg.instantiate(); Pkg.precompile(); "
ENTRYPOINT ["julia", "--project", "-e", "using GenieFramework; Genie.loadapp(); up(async=false);"]

```

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [November 26, 2024, 9:42am UTC](https://discourse.julialang.org/t/building-docker-image-on-a-machine-and-deploying-on-another-invalidates-precompile-cache/123086/2 "2024-11-26T09:42:22Z")

</div>

Set the `JULIA_CPU_TARGET` environment variable before precompiling, see [PkgServer.jl/Dockerfile at 90390794dd4a0eb65b2952970c6a5ccebb5871c3 · JuliaPackaging/PkgServer.jl · GitHub](https://github.com/JuliaPackaging/PkgServer.jl/blob/90390794dd4a0eb65b2952970c6a5ccebb5871c3/Dockerfile#L12-L15)

---

<div class="post-metadata">

### Author: ![benz0li](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benz0li/32/37040_2.png) [@benz0li](https://discourse.julialang.org/u/benz0li)
#### Post date: [November 26, 2024, 6:48pm UTC](https://discourse.julialang.org/t/building-docker-image-on-a-machine-and-deploying-on-another-invalidates-precompile-cache/123086/3 "2024-11-26T18:48:12Z")

</div>

See [julia-buildkite/utilities/build\_envs.sh at 33dbca22c2ed5be868ec08f343415580fd57238e · JuliaCI/julia-buildkite · GitHub](https://github.com/JuliaCI/julia-buildkite/blob/33dbca22c2ed5be868ec08f343415580fd57238e/utilities/build_envs.sh#L20-L94) to determine `JULIA_CPU_TARGETS` for different architectures.

---

<div class="post-metadata">

### Author: ![Pere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pere/32/214250_2.png) [@Pere](https://discourse.julialang.org/u/Pere)
#### Post date: [November 27, 2024, 11:07am UTC](https://discourse.julialang.org/t/building-docker-image-on-a-machine-and-deploying-on-another-invalidates-precompile-cache/123086/4 "2024-11-27T11:07:11Z")

</div>

That worked perfectly, thank you!
