cloudflared icon indicating copy to clipboard operation
cloudflared copied to clipboard

How to install cloudflared on Alpine linux?

Open ocodista opened this issue 2 years ago • 21 comments

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?

ocodista avatar Nov 23 '22 19:11 ocodista

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

sudarshan-reddy avatar Nov 23 '22 20:11 sudarshan-reddy

Hey @sudarshan-reddy thank you for the reply.

But unfortunately that didn't work either.

image

ocodista avatar Nov 23 '22 20:11 ocodista

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

ocodista avatar Nov 23 '22 20:11 ocodista

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

MPThLee avatar Dec 02 '22 19:12 MPThLee

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.

arthurfiorette avatar Jan 22 '23 00:01 arthurfiorette

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.

shahraizq avatar Jan 22 '23 01:01 shahraizq

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.

moiz-qureshi avatar Jan 22 '23 04:01 moiz-qureshi

image

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

arthurfiorette avatar Jan 22 '23 13:01 arthurfiorette

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.

MPThLee avatar Jan 22 '23 15:01 MPThLee

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

arthurfiorette avatar Jan 22 '23 15:01 arthurfiorette

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.

bktiel avatar Feb 20 '23 22:02 bktiel

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

YueMiyuki avatar Jul 21 '23 10:07 YueMiyuki

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...

qaqland avatar Aug 20 '23 08:08 qaqland

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"

felixmaker avatar Dec 29 '23 07:12 felixmaker

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

rxda avatar Jul 04 '24 06:07 rxda