I have a Dockerfile that builds some webpack stuff:
FROM node:21 as assets
COPY ...
RUN npm install
RUN npm run build
That produces a dist directory with roughly the following content:
webpack-stats.json
bundle.js
bundle.css
Now i have two Containers that need the result:
FROM python:latest
COPY --from=assets /app/dist/webpack-stats.json .
CMD python ...
FROM nginx:latest
COPY --from=assets /app/dist/ .
CMD nginx ...
However, those can’t be put in the same Dockerfile, since one Dockerfile only builds one image / container.
I also want to avoid running the build container twice to avoid inconsistency and long build times.
Is there a way to built only once, but use it in two containers?
2
Answers
So tag it.
And then build with
"Professionally" you would publish assets from a separate CI/CD into a private docker repository, like for example to gitlab project container registry, and use the full name in depende dockerfile.
This is why people have Docker Hub accounts. I didn’t try this, just rolled off the fingers.
In one directory you have Dockerfile containing
Now
Now in a different directory you have a Dockerfile containing this
in case you logged out
In a third directory you have a Dockerfile containing this
If you logged out of docker log back in and