docker-cloudflared icon indicating copy to clipboard operation
docker-cloudflared copied to clipboard

How do I use this?

Open Neriderc opened this issue 3 years ago • 1 comments

I'm wanting to run two instances of cloudflared so I can connect to two completely different domains. I'm hoping this container might help, but I just don't know where to start. I already have cloudflared running on my server for one of the domains, but I just can't get this working. Everyone else here seems much smarted than me, getting it working without any instructions, but I feel like I need a beginners guide.

Any tips on how to set this up?

Neriderc avatar May 25 '22 08:05 Neriderc

Ok so with a lot of playing and googling I've managed to get this working. For anyone that needs a bit of guidance, here's my docker-compose.yml file:

version: "3.8"
services:
  cloudflared:
    image: msnelling/cloudflared
    container_name: cloudflared
    restart: unless-stopped
    networks:
      - my_network
    command: cloudflared tunnel run <UUID>
    volumes:
      - ./cloudflared:/etc/cloudflared/
      - ./root:/root/.cloudflared/
    environment:
      - TUNNEL_HOSTNAME=domain.com
      - TUNNEL_URL=http://other_container:8001
networks:
  my_network:
    external: true

So first make sure you have a port exposed on the container you want to connect to. Here the port is 8001. You'll probably also need cloudflared installed outside docker so you can get the certs and create the tunnel. If you don't want to do that, comment out the environment variables, comment out the command and use the command sleep 1000 instead. This keeps the container running long enough to connect in and run from within the container. Connect to the container: docker exec -it cloudflared sh Then run cloudflare login to log in. Open the URL in a browser and do the login process and pick the website. Run cloudflare tunnel create tunnel_name to create a tunnel. Copy the UUID or find this by running cloudflared tunnel list Type exit to return to the host, then reverse your changes on the docker-compose.yml file as well as make the below changes:

  • my_network is the name of a network shared between cloudflared and the container you are connecting to. Presumed to be external but if you're setting this up as one big docker-compose.yml file you might want to change that.
  • other_container is the container name of the container you are trying to connect to.
  • <UUID> is the ID of the tunnel you are trying to connect to that we copied above.
  • Update TUNNEL_HOSTNAME to your domain. Make sure this matches what you picked when loggin in to Cloudflare.

Now start the container with docker-compose up -d and if you check the logs docker-compose logs -f then you should see output saying how it's successfully connecting to various data centres.

Neriderc avatar May 25 '22 22:05 Neriderc