DEV Community

sofaki000
sofaki000

Posted on

Run envoy proxy with docker

Hey friends, today we will do a short introduction how to run envoy proxy with docker. We will work with the basic blocks of envoy, which are listeners, clusters and filters.

Prerequisites

  1. download docker

Run envoy with docker

docker run --name=proxy-with-admin -d -p 9901:9901 -p 10000:10000 envoyproxy/envoy:v1.25.6

Why adding -p 9901:9901?
This exposes the 9901 container image to your host. This way you can access the admin portal in http://localhost:9901/.

Image description

From docker desktop, you can see in envoy.yaml which contains the configuration of your envoy, that admin portal is exposed on 9901 port on your container.
Image description

Send request to envoy

Envoy uses listeners to accept client requests. These requests are then forwarded to clusters, which represent your backend services.

In the envoy.yaml, we see the following configuration for listeners:

  listeners:
  - name: listener_0
    address:
      socket_address:
        protocol: TCP
        address: 0.0.0.0
        port_value: 10000
Enter fullscreen mode Exit fullscreen mode

This means that your listener is on port 10000. We have exposed this port with the Docker command: -p 10000:10000.

Therefore when you hit http://localhost:10000/ on your local machine, you reach the Envoy listener. When an Envoy listener receives a request, the Envoy filters execute.

In the filters section of our envoy.yaml we see:

   filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          scheme_header_transformation:
            scheme_to_overwrite: https
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match:
                  prefix: "/"
                route:
                  host_rewrite_literal: www.envoyproxy.io
                  cluster: service_envoyproxy_io
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
Enter fullscreen mode Exit fullscreen mode

From the "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
we see the type of filter we have applied, which is a HTTP connection manager more here

Your cluster (aka your backend) is service_envoyproxy_io.

Using Your Own envoy.yaml Configuration

If you want to use your own envoy.yaml configuration, you need to have an envoy.yaml file and provide it in the container image you are running.

Run this command in the folder where you have your envoy.yaml:

docker run --name=proxy-with-admin -d -p 9901:9901 -p 10000:10000 -v envoy.yaml:/etc/envoy/envoy.yaml envoyproxy/envoy:v1.25.6
The command -v .envoy.yaml:/etc/envoy/envoy.yaml is used to mount a file or directory from your local machine into a container. In this case, it mounts the local file .envoy.yaml to the path /etc/envoy/envoy.yaml inside the container. This ensures that the container uses the configuration file from your local environment.

References

- https://iceburn.medium.com/i-tried-getting-started-with-envoy-d6680f69bc3

Top comments (0)