Blog Detail

Envoy with Docker

By:DALEEP SINGH

2021-Jan-14 07:01:25

In previous write-up, we talked about what is Envoy and how to install and write a small and simple port-forwarding example. If we don’t want to install Envoy, we are given an option to create and deploy Envoy proxy as a container using Docker on the host. Envoy provides a Docker image available at https://hub.docker.com/r/envoyproxy/envoy. You can use docker command to pull the image and run a container.

# docker pull envoyproxy/envoy:v1.16-latest

I found this a pretty neat way to run and test your Envoy functionalities, without even installing it locally and no hassles of updating to a new version, which you have to, if you install it locally to the host.

I did give it a try and it is very easy to start, with all the required steps even mentioned in the official documentation ( https://www.envoyproxy.io/docs/envoy/v1.16.0/start/start#using-the-envoy-docker-image ). All you need is to create a small Dockerfile, which is pulling the Envoy proxy image from Docker Hub and running an instruction to COPY your config file to Envoy configuration path inside the image. Let’s go ahead and try to build this image and run some basic example. I thought of using the same first_example.yaml configuration, however, decided against it and used one example from Envoy documentation, modifying it slightly.

The Dockerfile definition:

FROM envoyproxy/envoy:v1.16-latest ## the parent image from Docker Hub

RUN apt-get update

COPY config.yaml /etc/envoy.yaml ## COPY config file to image while build is running

CMD /usr/local/bin/envoy -c /etc/envoy.yaml

CMD instruction in this Dockerfile is not necessary, as CMD is already set in the parent image used. I have put it here for the sake of Dockerfile completion. Below is the output from the image layers at Docker Hub.

The configuration I have used to demonstrate Envoy with Docker is working as a proxy, taking your request on specific port and forwarding it to the websites specified in the configuration. The official documentation example ( https://www.envoyproxy.io/docs/envoy/latest/configuration/overview/examples ) has been modified to route the request based on the prefix provided with the IP address for the proxy. If the request refers to the the prefix /google, the request is forwarded to www.google.com and if the request has prefix of /rh, it is routed to www.redhat.com .

I also included admin section in the configuration file so that now we can connect to the Admin console as well and check the status of the request and other statistics. We just need to point the browser to the envoy proxy IP address and port 9901. ( https://www.envoyproxy.io/docs/envoy/latest/start/quick-start/admin.html )

The configuration file is uploaded to the git repository at for your reference and the envoy-demo image is available for download from my Quay repository. Use command appended below to download and use the image.

#docker pull quay.io/dbais76/envoy-demo:v1.16

Now that we have the image ready with us, lets proceed to the next step to start our Envoy container and test the routing functionality. Since, as per the configuration proxy is listening on port 10000 and admin access is configured on port 9901, we will do port mapping while initializing the container.

#docker run -d --name envoy-route -p 10000:1000 -p 9901:9901 quay.io/dbais76/envoy-demo:v1.16

Now that we have the container running, I am going to get the current IP address assigned to it.

#docker inspect -f '{{ .NetworkSettings.IPAddress }}' envoy-route

On the web browser, if you try to open http://:10000, ( in our case, IP address is 10.88.0.2 ) it will give you an error message as shown in the image below.

Now to test and verify the configuration, let us try to access http://:1000/google and you should be routed to www.google.com and in the same manner, when accessing http://:1000/rh, we would be taken to www.redhat.com

Pretty cool, isn’t it.

Now we can even access the admin console on http://:9901 and we should be able to get statistics and configuration on the browser interface.

Hope this small demo would allow you to use Envoy docker image with your configuration and try new options.

Happy Reading !!