Deploy Serverless Docker Containers and Functions with Koyeb CLI
5 minThe Koyeb CLI (Command Line Interface) is now available and ready to let you manage all your Koyeb resources directly from your shell! The Koyeb CLI is a critical piece to improve the deployment experience and provide a fast way to interact with Koyeb when you develop your projects.
As engineers, we spend hours using the terminal, that's why we designed the CLI to be as simple and intuitive as possible. With the CLI, it's easy to automate and perform bulk actions without leaving the terminal. This first release allows you to quickly deploy Docker containers, configure Stacks and Secrets, invoke your functions, monitor your executions, and much more!
In this post, we will check how to use the CLI to:
Let's get started and try some of the cool features!
Getting Started
Installation
Koyeb CLI is available as pre-compiled
binaries for Linux, macOS and
Windows or as a go package. Once installed, the koyeb
command will be
available directly in your shell. Check out the installation instructions for more details!
Log in
Once installed, type: koyeb init
to create the CLI configuration.
The CLI will ask for a Koyeb API Token. You can generate one directly from the control panel.
Deploy and run Docker containers
Hello-world container
To deploy Docker containers with the CLI simply create a YAML file with your target configuration. We will start with a simple hello-world function in our configuration:
We can now create a new stack called hello-stack with
koyeb create stack -n <stack_name>
and
deploy our configuration with koyeb create revision <stack_name> -f <config.yaml>
.
Your stack is deployed, let's check the status with
koyeb get revision <stack_name>
:
If your stack is in the BUILDING
state, just wait a few seconds for the
deployment to complete.
To invoke the function use koyeb invoke function <stack_name> <function_name>
.
You can get the logs streamed as it executes with --tail
:
Et voilà! You know how to deploy and invoke functions.
Sending events and parameters with Koyeb CLI
We will deploy a second function called fetch-api which fetches data
from an API. The API to scrap will be determined from the event received.
To do that, we will use the stedolan/jq
Docker image to read the correct field
in our JSON event.
Let's modify our koyeb.yaml
file as follow:
We can now deploy this new version of our stack with
koyeb create revision hello-stack -f koyeb.yaml
and follow the deployment with
koyeb get revision
:
We will now invoke our function with the url
to scrap. Koyeb uses the
cloudevent specification to define events format. You
can use YAML or JSON to write events which will be sent to your function. We
will create an event.yaml
file and request to fetch the GitHub API with the following content:
Let's now invoke the function with this event:
You now know how to easily invoke your functions directly from your shell!
Deploy Python and Node.js functions
You can also use the Koyeb CLI to invoke code functions and containers deployed from GitHub.
Instead of using koyeb create stack
, you simply need to connect your GitHub repository
through the web interface and add a
koyeb.yaml
file in your repository. The deployment will be automatically done
each time you git push
. You can read more about the GitHub
integration in our
documentation.
You can use koyeb get revision
and koyeb invoke function
in the same way as
for other stacks.
Start using Koyeb CLI today!
The Koyeb CLI is written in Go and is completely open-source. Comments, feature requests and contributions are always welcome!
We're happy to provide 1000 hours of compute, 1TB of storage, and 5TB of bandwidth per month for free until the end of the year! Sign up now
As always, we're available through our support channel, our community platform or through our integrated instant messaging system if you have a question or want to share feedback.