Pull a Discourse Base Docker Image from a Localhost Registry

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:

  1. Setup a local (localhost) Docker registry,
  2. Tag a Discourse base image and push that Discourse base image to a local registry,
  3. 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.
2 Likes

Additional Notes:

Instead of tagging the original Discourse base images, we can commit an image from a running container to get a new image id:

docker run -it discourse/base:2.0.20200512-1735  bash

in another terminal window:

root@localhost:~# docker ps -a
CONTAINER ID        IMAGE                                   COMMAND                  CREATED             STATUS                     PORTS                    NAMES
dc853b4afb35        discourse/base:2.0.20200512-1735        "bash"                   8 minutes ago       Exited (0) 4 minutes ago                            upbeat_shirley
1d265eeb7441        registry:2                              "/entrypoint.sh /etc…"   24 hours ago        Up 7 hours                 0.0.0.0:5000->5000/tcp   registry

then commit this base container:

docker commit dc853b4afb35  localhost:5000/base:2.0.20200512-1735

and then push this newly tagged image to our local registry:

docker push localhost:5000/base:2.0.20200512-1735

This avoids the issue of having multiple image tags (id) and prepares us for (future experiments) making changes to our local base Discourse image and committing those changes.

1 Like

After testing this configuration numerous times, I am getting inconsistent results building Discourse from a local registry base image.

There seems to be something I'm missing. If anyone knows why or what, please post and let me know.

My current "guess" is that there is some conflict related to Docker images and containers; but I cannot put my finger on the issue.

Thanks.

"Inconsistent" suggests that sometimes something works and at other times it doesn't.

What sort of inconsistency are you experiencing?

Sometimes the app "works" when I pull the base image from the localhost registry; and sometimes I get "refused to connect" errors and no pages work at all; but I have not been able to find out what is causing the problem.

I have tried deleting all docker containers and images (except the local registry docker container, of course) and rebuilding.

It worked for a while, but now it's not working and I'm not willing to spend the time to debug it since it is not mainstream and totally unsupported at meta. In fact, I get the feeling they might even disapprove of this kind of experimentation and "hacking around" with Discourse images and posting about it over there at meta.

I don't want to waste a lot of time and effort "hacking the install" if it is not going to benefit other sys admins and / or cause friction.

Not everyone is so "curious" and likes 'breaking things" and seeing the boundaries of systems etc.

I've had similar issues building a platform without Docker. There are a number of config files that need to be edited particularly with regards FQDN, "server hosting the app", etc.

I'll take a look at my notes and see whether I can suggest anything that might be causing it.

I don't have any issues if I use the standard launcher config and pull the base docker images from the discourse docker hub.

I only have issues when I pull the same image from a local (private) registry.

So, I don't think it is related to FQDN. but of course, I could be wrong.

I have had problems in the past when I build with LETSENCRYPT over and over, LETSENCRYPT stops giving me certs (it seem like it is rate limiting) but when I check the "rules" I am no where close to the LETSENCRYPT weekly limit per domain.

Actually, it seems to work "OK" when I used docker tag and pushed the newly tagged image to my private registry.

However, when I switched to docker commit things began to break down, for some reason.

I lost interest to debug this, when I got the cold shoulder over at meta for experimenting in this way, to be honest.

This kinds of "experiments" do not seem to be appreciated, and I only started down this "experimental" path because another user over there asked about something similar (out of mainstream, unsupported).

Yes, I can believe that.

You are working on a Mac?

No. I don't do Docker on the Mac.

This "experiment" is being performed on a Linode Ubuntu server.

When I develop plugins (do not use Docker), I am always on my macpro (desktop).

Honestly @hicksd8,

I think I can debug and get this working, but for what ends?

This configuration (pulling the Discourse base image from a local Docker registry) is so far out of mainstream Discourse meta, even the "hacker guy" I was trying to help out, did not show any interest, so I'm moving on for now.

Actually, I understand... this is just a "hack" and nothing more, really.

Anyway, I just checked and I'm having a problem on this staging server with LETSENCRYPT and not the local docker registry.

This problem has been causing me problems for days. I think I hit some kind of "rate limit" for certs.

I"m going to give this a rest......