Deploy a Docker Container

Last updated about 2 months ago

Koyeb natively allows you to run your own, pre-built containers. With containers, you can embed all the system dependencies you need.

This is actually what we did in the Your first Stack guide. This time we will use a raw ubuntu Docker image to experiment.

Docker Containers and Custom Commands

This example will execute cat /koyeb/events/in/raw in an ubuntu Docker container each time the Koyeb Function is invoked. The /koyeb/events/in/raw is a Koyeb generated file, which is always present in your containers and contains data about the event that triggered the execution in JSON format.

Our example will display the content of the event received by the container on stdout, which is readable in the logs.

Deploy a New Revision with a Custom Command

  1. Create a new stack
  2. Copy and paste the following content:
1functions:
2  - name: "hello-container" # The function name
3    image: ubuntu # The Docker image to use
4    command: ["cat"] # Overrides the container default command
5    args: ["/koyeb/events/in/raw"] #  The arguments of the command
6

The command option of the YAML file allows you to override the default command specified with CMD in the Dockerfile of the container.

The args option allows you to provide arguments to the default CMD of the Dockerfile or the command you provided.

  1. Deploy the revision

Invoke Your Docker Container

Now, you can Invoke your function with the pre-filled {"hello": "world"} event data.

  1. Click Invoke
  2. Make sure the Invoke modal contains {"hello": "world"}
  3. Click Submit
  4. Click Show Logs

In your log files, you should see a JSON similar to: Invoke Docker

If you forgot how to invoke your function or read logs, please refer to the invoke section of the Your First Stack Guide.

Local testing

1docker run
2

Deploying from a private registry

At the moment, we only support the official public Docker registry, but support for private registries is on the way! If you are interested in support for private registries, please do not hesitate to contact us about your needs.

footer-frame