I have two diaries, one of what I eat the other is this one :e.

Redirect Docker container to domain using Cloudflare

Now that we have created a working WordPress container would be great if we can use our domain in it.

In this example I’m going to redirect the WordPress container to the domain Azores-shipping.pt using Cloudflare Tunnel, this way I don’t need to open any port or expose my computer/network to the internet, Cloudflare Tunnel works almost like a VPN for website, the docker container will serve the WordPress website to Cloudflare and Cloudflare will serve the WordPress container to the world.

1st you need to go to www.cloudflare.com, register and add your domain. Cloudflare will ask you to change your dns settings for you domain so it can control the dns it. (you can see here how to do it)


Go to ‘Access’ on your cloudflare sidebar and click ‘Launch Zero Trust’

Select ‘Access’ and then ‘Tunnels’, here you can click to create your new tunnel that will connect the docker container with WordPress to this domain, you can give any name you want to this tunnel.

After you will be presented with a command line to install the tunnel, you can select several Operation Systems, all we need is the token, so just copy the random string after ‘–token’

You can after copying your Token click next, you will be asked some more details, here you can select the domain to witch this tunnel will redirect and the service that is the address of this service running on your pc. In this example the address for our WordPress container is http://shipping:81 (container called ‘shipping’ on port 81) and this will be accessible by the public by navigating to https://azores-shipping.pt

Finally you run the docker run command to start the tunnel. don’t forget the tunnel must also be in the same network as your WordPress container, in this example the network is ‘sites’ the tunnel container name will be ‘cloud_shipping’ and the local address to send to cloudflare is http://shipping:81

docker run -d --name cloud_shipping \
--network sites \
cloudflare/cloudflared:latest tunnel --no-autoupdate run --url http://shipping:80 --token eyJhIjoiZmRjYWE0YmZhNjhmMDAyMGFkM2Y0Mjk3ZjZlZDMwMTYiLCJ0IjoiZGIwMjQ5ZTUtYTk1YS00MzFjLTg0NzgtODZhOGRjOGI3MTlhIiwicyI6Ik5qSmtZbVprTlRjdFpURmhNeTAwWldOakxXSmxOVGN0TWpjMU1qUXdPREfdghsdfgdsf

Leave a Reply

Your email address will not be published. Required fields are marked *