Docs
Try Apollo Studio

Docker and the router

Using docker to run router images


The default behaviour of the router images is suitable for a quickstart or development scenario. You'll need to know how to customize this default behaviour if you wish to do any of the following.

Note: The Apollo Router is made available under the Elastic License v2.0 (ELv2). Read our licensing page for more details.

Note: The docker documentation for the run command may be helpful when reading through the examples.

Note: The exact image version to use is your choice depending on which release you wish to use. In the following examples, replace <image version> with your chosen version. e.g.: v1.4.0

Override the configuration

Our default Docker images include a basic configuration which can be seen in our repository. Inside the container, this file is located at /dist/config/router.yaml.

If you wish to override the default configuration, it is important to consider and preserve aspects of the default configuration. In particular, it is generally important for the Router to bind to the special "listening address" of 0.0.0.0 (i.e., "all interfaces") to ensure the Router is exposed on a the network inferface accessible outside of the local container; without this configuration, the Router will only listen on localhost.

You can provide your own configuration from the host environment to the Router by mounting your configuration to /dist/config/router.yaml, as follows:

docker run -p 4000:4000 \
--env APOLLO_GRAPH_REF="<your graph>" \
--env APOLLO_KEY="<your key>" \
--mount "type=bind,source=/home/user/router.yaml,target=/dist/config/router.yaml" \
--rm \
ghcr.io/apollographql/router:<image version>

Note: Both local and container paths must be specified as absolute paths.

In this case we are mounting a file from the host system (/home/user/router.yaml) in place of the default configuration provided in the image at /dist/config/router.yaml.

Passing command-line arguments to the Router binary

By default, the router command invoked inside the published container does run not set any of the available command-line arguments. If you want to set any of the available options, pass the desired options at end of the docker run command. For example, to start the Router using the --log debug argument, you can use the following docker run command:

docker run -p 4000:4000 \
--env APOLLO_GRAPH_REF="<your graph>" \
--env APOLLO_KEY="<your key>" \
--rm \
ghcr.io/apollographql/router:<image version> --log debug

Debugging your container

If you run the debug image, then it's easy to debug your container:

docker run -p 4000:4000 \
--env APOLLO_GRAPH_REF="<your graph>" \
--env APOLLO_KEY="<your key>" \
--mount "type=bind,source=/router.yaml,target=/dist/config/router.yaml" \
--rm \
--interactive \
--tty \
--entrypoint=sh
ghcr.io/apollographql/router:<image version>-debug
/dist # pwd
/dist
/dist # ls
LICENSE config router
README.md licenses.html schema
/dist # exit

In this case, we've added interactive and tty flags and changed the entrypoint of the image to be a shell.

Specifying the Supergraph

If we don't want to use uplink to retrieve our subgraph, we can manually specify the details.

docker run -p 4000:4000 \
--mount "type=bind,source=/docker.graphql,target=/dist/schema/local.graphql" \
--rm \
ghcr.io/apollographql/router:<image version> -c config/router.yaml -s schema/local.graphql

Note: In this example we have to mount the local definition of the supergraph into our image AND specify the location of the file. It doesn't have to be mounted in the /dist/schema directory, but it's a reasonable location to use. We must specify the configuration file location as well, since overriding the default params will override our default config file location. In this case, since we don't want to change our router configuration but want to make sure it's used, we just specify the default location of the default configuration.

Building your own container

This section is aimed at developers familiar with tooling such as docker and git who wish to make their own DIY container images. The script documented here is not a part of the router product, but an illustrative example of what's involved in making your own images.

In the dockerfiles/diy directory, we now provide a script, build_docker_image.sh which illustrates how to build your own docker images from either our released tarballs or from a git commit hash or tag. Here's how to use it:

% ./build_docker_image.sh -h
Usage: build_docker_image.sh [-b] [<release>]
-b build docker image from a repo, if not present build from a released tarball
<release> a valid release. If [-b] is specified, this is optional
Example 1: Building HEAD from the repo
build_docker_image.sh -b
Example 2: Building tag from the repo
build_docker_image.sh -b v1.4.0
Example 3: Building commit hash from the repo
build_docker_image.sh -b 1c220d35acf9ad2537b8edc58c498390b6701d3d
Example 4: Building tag v1.4.0 from the released tarball
build_docker_image.sh v1.4.0

Note: The script has to be run from the dockerfiles/diy directory because it makes assumptions about the relative availability of various files. The example uses distroless images for the final image build. Feel free to modify the script to use images which better suit your own needs.

Edit on GitHub
Previous
Overview
Next
Kubernetes