telepresenceio / telepresence

Local development against a remote Kubernetes or OpenShift cluster
https://www.telepresence.io
Other
6.43k stars 507 forks source link

Unable to install and run telepresence inside a docker container #3610

Closed devashish2203 closed 3 weeks ago

devashish2203 commented 4 weeks ago

Describe the bug

I am trying to setup telepresence inside a docker container to run on CI. But when running the telepresence binary I get the following error

/bin/sh: telepresence: not found

To Reproduce For this I setup a simple Docker image using the following Dockerfile based on https://github.com/telepresenceio/telepresence.io/blob/master/docs/pre-release/reference/inside-container.md#running-the-container

Dockerfile

# Dockerfile with telepresence and its prerequisites
FROM alpine:3.13

# Install Telepresence prerequisites
RUN apk add --no-cache curl iproute2 sshfs

# Download and install the telepresence binary
RUN curl -fL https://app.getambassador.io/download/tel2oss/releases/download/v2.18.0/telepresence-linux-amd64 -o telepresence
RUN chmod a+x telepresence

Then I'm building the container on an Ubuntu 22.04 machine

docker build . -t telepresence-ci

Next I'm running the above container using

docker run --network=host --cap-add=NET_ADMIN --device /dev/net/tun:/dev/net/tun -it --rm telepresence-ci

# Also tried
docker run --network=host --privileged -it --rm telepresence-ci

Once inside the container when trying to run telepresence

telepresence version

The following error is shown

/bin/sh: telepresence: not found

Expected behavior Expect to see the following output

OSS Client : v2.18.0
Root Daemon: not running
User Daemon: not running

Versions (please complete the following information):

VPN-related bugs: N/A

Additional context The same version of the teleport binary works fine on the host Ubunut machine

> curl -fL https://app.getambassador.io/download/tel2oss/releases/download/v2.18.0/telepresence-linux-amd64 -o telepresence
> chmod a+x telepresence
> telepresence version
OSS Client : v2.18.0
Root Daemon: not running
User Daemon: not running

In a different docker image where the base image is Ubuntu 22.04 instead of alpine, a similar error is seen

telepresence
bash: /usr/local/bin/telepresence: cannot execute: required file not found
thallgren commented 4 weeks ago

IN order to run Telepresence in an alpine container, you'll need the following:

RUN apk add --no-cache ca-certificates iptables iptables-legacy bash
RUN rm /sbin/iptables && ln -s /sbin/iptables-legacy /sbin/iptables
RUN rm /sbin/ip6tables && ln -s /sbin/ip6tables-legacy /sbin/ip6tables

Not sure about alpine:3.14 though. The current version is 3.20.

thallgren commented 4 weeks ago

In general, I'd suggest using telepresence connect --docker to start the telepresence daemon container and then telepresence intercept --docker-run to start containers that reuses the network established by that daemon.

devashish2203 commented 4 weeks ago

Thanks. I'll try out on the latest alpine and the above additional dependencies and report back.

For the other suggestion regarding telepresence connect --docker. My end goal is to run telepresence on a docker runner in Gitlab CI, so not sure if the daemon container method would work there.

devashish2203 commented 4 weeks ago

Seeing the same issue with alpine:3.20 and the above added dependency. My dockerFile now is

# Dockerfile with telepresence and its prerequisites
FROM alpine:3.20

# Install Telepresence prerequisites
RUN apk add --no-cache curl ca-certificates iptables iptables-legacy bash sshfs iproute2
RUN rm /sbin/iptables && ln -s /sbin/iptables-legacy /sbin/iptables
RUN rm /sbin/ip6tables && ln -s /sbin/ip6tables-legacy /sbin/ip6tables

# Download and install the telepresence binary
USER root
RUN curl -fL https://app.getambassador.io/download/tel2oss/releases/download/v2.18.0/telepresence-linux-amd64 -o telepresence
RUN chmod +x ./telepresence

And then I am running

> docker build . -t telepresence-cli
> docker run --network=host --cap-add=NET_ADMIN --device /dev/net/tun:/dev/net/tun -it --rm telepresence-cli

Inside the container

/ # ./telepresence
/bin/sh: ./telepresence: not found
/ # ./telepresence version
/bin/sh: ./telepresence: not found
devashish2203 commented 4 weeks ago

Using an Ubuntu 22.04 base container I was able to run telepresence. My Dockerfile below.

# Dockerfile with telepresence and its prerequisites
FROM ubuntu:22.04

RUN apt-get update
RUN apt-get install -y curl ca-certificates sshfs
# Download and install the telepresence binary
RUN curl -fL https://app.getambassador.io/download/tel2oss/releases/download/v2.18.0/telepresence-linux-amd64 -o telepresence
RUN chmod +x ./telepresence
thallgren commented 3 weeks ago

Ah, yes. The alpine image doesn't contain the same libc. You need to add this:

RUN apk add libc6-compat

You'll see what the binary needs by doing:

ldd ./telepresence

Good info about this in the first reply to this Stack Overflow question.

devashish2203 commented 3 weeks ago

Thank you for the pointers. The stack overflow link is particularly helpful to understand what was going on. Closing this issue now.