Curious by a Discourse meta topic (see reference), I wanted to explore how to pull a Discourse base image locally (localhost) instead of from a remote Docker hub.
It turns out this is quite easy and in this post, I will describe how to:
- Setup a local (localhost) Docker registry,
- Tag a Discourse base image and push that Discourse base image to a local registry,
- Add this local Discourse base image to
launcher
and pull this local image into a Discourse build.
This is actually easier than it sounds.
First, we create a new container, which becomes our local Docker registry :
docker run -d -p 5000:5000 --restart=always --name registry registry:2
Now, we have a local Docker image registry running. How easy is that!
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1d265eeb7441 registry:2 "/entrypoint.sh /etc…" 2 hours ago Up 2 hours 0.0.0.0:5000->5000/tcp registry
Next, let's look in the Discourse launcher
script and what is the current base image:
# grep discourse/base launcher
image="discourse/base:2.0.20200512-1735"
If Discourse is already up and running, we have this Docker image on our server already:
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
local_discourse/app latest 407671978486 3 minutes ago 2.62GB
discourse/base 2.0.20200512-1735 991acdba0b1f 4 weeks ago 2.22GB
registry 2 708bc6af7e5e 4 months ago 25.8MB
So we are nearly good to go. We simply tag a base image, as follows:
# docker tag discourse/base:2.0.20200512-1735 localhost:5000/base:2.0.20200612-1735
and we can of course check the image:
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
local_discourse/app latest 407671978486 6 minutes ago 2.62GB
discourse/base 2.0.20200512-1735 991acdba0b1f 4 weeks ago 2.22GB
localhost:5000/base 2.0.20200512-1735 991acdba0b1f 4 weeks ago 2.22GB
registry 2 708bc6af7e5e 4 months ago 25.8MB
Now, we simply push this newly tagged image to our local Docker repo:
# docker push localhost:5000/base:2.0.20200512-1735
All we need to do next to so edit launcher
and change:
image="discourse/base:2.0.20200512-1735"
to:
image="localhost:5000/base:2.0.20200512-1735"
and when do rebuild Discourse again, it will pull the Discourse base image from our local Docker registry.
# /var/discourse/launcher rebuild app
It's that easy.
In a future post, when I have time, I'll experiment with making changes to our local Discourse base images and see what I can break (or fix)!
References:
Notes:
- It is a good idea to make sure we delete duplicate Docker images before rebuilding app(s). When I rebuilt, when experimenting, using a "clean slate" by removing older images, I got the best results.