How to build local docker image of Ghost?

I am trying to solve a issue where i need to build the ghost image. Is there any way i can achieve that?

What exactly is the issue you are facing?

We have a bug fix for the issue, Type error within hash function during setting up Ā· Issue #16918 Ā· TryGhost/Ghost Ā· GitHub and to test it locally we need to build the docker image locally. Wanted to know if there is a way to achieve this?

This is the current Dockerfile (5.71.0).

You can build the docker image locally by duplicating and editing it.

Here’s how I’d do it:

  1. Build your local fix with yarn archive: Ghost Docs
  2. Edit the Dockerfile to copy the local .tar archive to the build filesystem
  3. Edit line 55 to use the local archive rather than a downloaded remote version. You can use the --archive flag for that, which is mentioned here under ā€œOptionsā€.
  4. Run the docker image.
1 Like

I am getting the following error while running the build command

Debug Information:
OS: Debian GNU/Linux, v11
Node Version: v18.18.2
Ghost-CLI Version: 1.25.3
Environment: production
Command: ā€˜ghost install --archive ghost/core/ghost-5.70.2.tgz --db mysql --dbhost mysql --no-prompt --no-stack --no-setup --dir /var/lib/ghost’
Message: A supported archive file could not be found.

Looks like you haven’t actually copied the archive to the Docker file system.

You need to do that, so whatever commands you write inside your Dockerfile can actually access it. If it’s still on your host file system, docker will not have access to that.

Here’s the documentation on that: Dockerfile reference | Docker Docs

In practice, it will look somewhat like this (this is directly from the Dockerfile I use to build custom docker images for Magic Pages, the Ghost host I am running):

# Copy custom ghost archive to /tmp
COPY /path/to/archive/archive.tgz /tmp

# Install Ghost from archive
RUN ghost install --archive /tmp/archive.tgz --no-prompt --no-setup --no-start

So, obviously you will need to adapt that a bit – but you get the idea :smiley:

1 Like

@jannis I am facing the same issue as TS.
The archive definitely gets into the image during the building process from previous stage, still no luck.
Apart from that, I get the same error if I just pull the official repo locally and run:
$ npm install --global nx
$ yarn install
$ yarn archive
$ ghost install --archive ./ghost/core/ghost-5.74.5.tgz --dir ~/ghost_installed

Result:
Message: A supported archive file could not be found.
Debug Information:
OS: Debian GNU/Linux, v12
Node Version: v18.19.0
Ghost-CLI Version: 1.25.3
Environment: production

The archive path and name are absolutely correct. Any ideas what is going wrong?

Hey Sergei!

I managed to replicate this and played around a little bit. Interestingly, it worked when I provided an absolute path for the archive:

ghost install --dir ~/ghost_instatlled --archive /Users/jannis/blabla/ghost/core/ghost-5.74.5.tgz

(obviously replace the /Users/jannis/blabla with the location of your Ghost directory)

Not entirely sure why though. I had a look at the CLI’s source code and this logic should mitigate that behaviour, in my opinion:

So, can’t get to the bottom of it right now, but using the absolute path should fix it for you :smiley:

1 Like

@jannis
Changing the relative path to the absolute one worked like a charm :smiley:
Thank you!

1 Like