Deploy a Docker container

Last updated 6 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:
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

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.

Deploying from any public or private registry

To read about deploying from your Private Docker Container Registry or an other public Container Registry, go to our Deploy from any Docker Container Registry.

Ready to get started?

Get in touch or create an account and deploy your serverless stack in minutes.