Unable to set url ENV variable in docker container

I was originally using Ghost 0.11.x and figured it was time to upgrade to the latest version. I ran the docker container 1.0 and imported my stuff, and then ran the container for 2.0 (had a mounted volume so data persisted). This more or less worked, but a lot of the urls were broken, using localhost:2368 instead of my blog url. I looked it up and saw that I’m supposed to use -e url=https://domain.here but that didn’t work. For some reason, that particular environment variables causes it fail.

I’m not sure if this is affecting it, but my ghost container is also behind a Caddy reverse-proxy. My domain maps to my server IP, from which Caddy maps the request to that domain to the docker container IP. e.g.

blog.domain.com {
    proxy / 172.17.0.7:2368
}

Now, when I run the following docker command: docker run -d --name ghost -v /home/ghost:/var/lib/ghost/content ghost, it starts fine. When I navigate to blog.domain.com, Caddy routes everything correctly and I see my blog. But the links are broken like I mentioned, going to http://localhost:2368/etc.

When I run docker run -d --name ghost -e url=https://blog.domain.com -v /home/ghost:/var/lib/ghost/content ghost, everything breaks. Attempting to navigate to blog.domain.com hangs for a while, then the url changes to https://172.17.0.7:2368/ and fails to connect.

This only happens when I use the url environment variable. I tried other combinations, including the port flag, setting the NODE_ENV variable, using 1-alpine instead of 1, etc. Nothing worked.

How do I get past this? I don’t want to run ghost outside of a docker container, but there doesn’t seem to be many resources on how to fix this issue, as everyone points to that environment variable, but it’s not working here.

I originally had this problem because I wasn’t using ‘url’ as all lower case in my environment variable. It looks like you might not have that problem, but I’m mentioning it just in case it is helpful.

Yup I saw that come up while searching for a solution, I tried both -e url=https://blog.domain.com and -e URL=https://blog.domain.com, neither worked.

Bumping in case anyone new can help. I thought perhaps the theme was the issue but im sure ghost itself is having issues using the url properly. When not setting the environment variable, it tries using localhost:2368 still, even on the ghost admin page.

Hi,
I maintain a docker image for Ghost. It’s a fork from the official docker image.

It works using url=http://localhost:2368

GHOSTFIRE_IMG="devmtl/ghostfire:stable"

docker run -d \
—name ghostblog \
-p 2368:2368 \
-e url=http://localhost:2368 -e NODE_ENV=production \
-v /myuser/localpath/ghost/content:/var/lib/ghost/content \
${GHOSTFIRE_IMG}

That looks really interesting - I know that I’ve had some problems running the standard docker image under Azure and getting persistent data. I think it might be down to some magic with setting the volume correctly and your configuration there has given me an idea :slight_smile:

What does setting the url to localhost:2368 do? Or are you saying I can set the url to my actual domain and it works correctly?

That’s correct - http://localhost:2368 is the default domain used by ghost :)

Cool. Let me know if something is not clear enough in the README :-p

Yes sir!

This http://localhost:2368 is when you run it locally on your mac/pc

Ah but the issue is that I need to be mapped to a domain, I’m running ghost on a digital ocean droplet and want to access it via the domain i have.

This is a simple DNS config. You should google for “how to host my own blog on digital ocean”. “How to have my blog behind cloudflare”.

You should be fine with some work around these topics :slight_smile:

I tried using your fork and I ran into the same issue. If I leave the url parameter as localhost:2368, then the site is broken as links to the homepage or back to the site from the editor will try going to localhost:2368 instead of the url I want. If I set the url parameter to my domain, the site redirects to https://172.17.0.5:2368/ (the container ip) upon connecting, and fails to connect. I’m pretty sure the DNS is setup properly as I’m doing the same thing I did for my ghost v0.11 instance (DNS from domain registrar points to my droplet IP, and from there Caddy proxies requests to the corresponding container).

I ended up finding the fix, instead of copy-pasting I’ll link to the issue I made: Running behind Caddy Reverse Proxy (originally thought was an issue with URL flag) · Issue #169 · docker-library/ghost · GitHub

I see you had a proxy issue. It’s always the case :-p

Seriously, the docker image is stable for over 2 years and my guess is that 1000s of people are using/testing it every day. The docker image I maintain has been pulled more than 5M times (I’m like what? really ?).

@ROODAY is there something I could improve in the README regarding the proxy stuff you were messing around?

I think just adding a note that people using it behind proxies should try running it as transparent. I’m not exactly sure why it works, perhaps someone more knowledgeable on the topic can chime in. The caddy docs has a little bit on what transparent does on this page: https://caddyserver.com/docs/proxy (just scroll down a bit).

My only question now I guess is what changed in ghost that required the transparent directive, would be useful to identify in other projects to avoid this headache later.

If you had told me you were using Caddy, I would have you check this example : examples/Caddyfile at master · caddyserver/examples · GitHub

I don’t know why the transparent argument is needed.

Cheers!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.