cloudflare / cloudflared

Cloudflare Tunnel client (formerly Argo Tunnel)
https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide
Apache License 2.0
9.4k stars 837 forks source link

How to install cloudflared on Alpine linux? #821

Open ocodista opened 2 years ago

ocodista commented 2 years ago

I see that the binaries link are https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64

But what's the extension of this file?

How can I install it on alpine linux?

docker run -it alpine

apk add --no-cache curl

curl -s -O https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64

tar zxvf cloudflared-linux-amd64

Does not work, any tips?

sudarshan-reddy commented 2 years ago

That’s the binary. You can just run it without unzipping it.

ocodista commented 2 years ago

Hey @sudarshan-reddy thank you for the reply.

But unfortunately that didn't work either.

image

ocodista commented 2 years ago

Code tried

docker run -it alpine

apk add --no-cache curl

curl -s -O https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64

chmod +x ./cloudflared-linux-amd64
./cloudflared-linux-amd64 -v
MPThLee commented 2 years ago

Could you try install libc6-compat package in apk? I had no issue.

arthurfiorette commented 1 year ago

To anyone who got here.

curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/bin/cloudflared

It was missing the -L flag.

shahraizq commented 1 year ago

To anyone who got here.

curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/bin/cloudflared

It was missing the -L flag.

Thanks I literally Just got here looking to deploy cloudflared on alpine linux.

moiz-qureshi commented 1 year ago

To anyone who got here.

curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/bin/cloudflared

It was missing the -L flag.

any idea how I can run the cloudflare as a service on alpine linux? I want the tunnel to be running in the background upon boot.

arthurfiorette commented 1 year ago

image

Do that and execute cloudflared service install <key that i blurred on image>, cloudflared will self install after it.

MPThLee commented 1 year ago

Just in case you may not know. Alpine has own cloudflared build on aports repository. But it is on testing branch (which is disabled by default on apk configuration), And the build is not by cloudflare. It is build from source by their build system.

arthurfiorette commented 1 year ago

Yeah I saw that, but i was on the testing branch... Would it make any difference?

bktiel commented 1 year ago

To anyone who got here.

curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/bin/cloudflared

It was missing the -L flag.

any idea how I can run the cloudflare as a service on alpine linux? I want the tunnel to be running in the background upon boot.

For anyone else who stumbles on this thread and follows that solution, cloudflared service install ... installs a sysv service alpine doesn't know what to do with. You'll need to create a valid one if you want an alpine service. Here's a bare example:

#!/sbin/openrc-run

name=$(basename $(readlink -f $0))
cfgfile="/etc/$RC_SVCNAME/$RC_SVCNAME.conf"
command="/usr/bin/cloudflared"
command_args="--pidfile /var/run/$name.pid --autoupdate-freq 24h0m0s --config /etc/cloudflared/config.yml tunnel run"
command_user="root"
pidfile="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"
command_background="yes"

Sticking it as /etc/init.d/cloudflared and then rc-update add cloudflared default should set it to work as expected.

YueMiyuki commented 1 year ago

Sticking it as /etc/init.d/cloudflared and then rc-update add cloudflared default should set it to work as expected.

Just in case someone is using Alpine Base image, rc-update it a part of openrc, so you need to install it manually by running: apk add openrc

qaqland commented 1 year ago

Cloudflared doesn't support multi tunnel with one config file, so I use softlinks to make services.

Here are my /etc/init.d/cloudflared and /etc/conf.d/cloudflared

~ $ cat /etc/init.d/cloudflared
#!/sbin/openrc-run

name=${RC_SVCNAME}
command=/usr/bin/cloudflared
command_user=cloudflared:cloudflared # maybe should change
command_background="yes"
pidfile=/run/${RC_SVCNAME}.pid

# output_log="/var/log/${RC_SVCNAME}.log"
# error_log="/var/log/${RC_SVCNAME}.err"

depend() {
        need net
        after firewall
}
~ $ cat /etc/conf.d/cloudflared
command_args="tunnel --config /etc/cloudflared/${RC_SVCNAME##*.}.yml run"

When need to start a new tunnel service, just create two softlinks in both init.d and conf.d

ln -s cloudflared cloudflared.example

and write config file at /etc/cloudflared/example.yml.

Then it can be used as normal:

rc-service cloudflared.examplle start...
felixmaker commented 11 months ago

What's more, if you Create a remotely-managed tunnel (dashboard), you can change command_args into:

command_args="--pidfile /var/run/$name.pid  --autoupdate-freq 24h0m0s tunnel run --token YOUR_TOKEN"
rxda commented 5 months ago

rc-update add cloudflared default One more command is needed chmod +x /etc/init.d/cloudflared

mikemusni commented 3 months ago

curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/bin/cloudflared chmod +x /usr/bin/cloudflared usr/bin/cloudflared -v

and here is the complete installation.

Screenshot 2024-08-20 at 2 57 01 PM
arthurfiorette commented 3 months ago
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/bin/cloudflared
chmod +x /usr/bin/cloudflared
usr/bin/cloudflared -v