Skip to main content
Version: 1.25

Docker Compose on Kubernetes with Okteto

This tutorial will show you how to develop an application with Okteto using Docker Compose files. Docker Compose are for developers who don't want to deal with the complexities of Kubernetes manifests. Okteto implements and extends the Compose Specification to make it easy to develop Docker Compose applications on Kubernetes.

Prerequisites

Step 1: Deploy your Development Environment

Get a local version of the Sample App by executing the following commands:

$ git clone https://github.com/okteto/compose-getting-started
$ cd compose-getting-started

The Sample App is a simple web application implemented using Python, with Redis for storage. The docker-compose.yml file defines the components of the Sample App:

services:
vote:
build: vote
scale: 2
environment:
- FLASK_ENV=development
command: python app.py
ports:
- 8080:8080
volumes:
- ./vote:/src

redis:
image: redis
ports:
- 6379
volumes:
- redis:/data

volumes:
redis:

The equivalent Kubernetes manifests would have more than 300 lines of yaml!

Deploying the Sample App is as simple as executing this command:

$ okteto deploy
 i  Using cindy @ okteto.example.com as context
✓ Deploying compose
i Endpoints available:
- https://vote-cindy.okteto.example.com/
✓ Development environment 'compose-getting-started' successfully deployed

The deploy command will create the necessary deployments, services, persistent volumes, and ingress rules needed to run the Sample App. Cool no 😎?

Open your browser and go to the URL of your development environment, shown as part of the okteto deploy logs (https://vote-cindy.okteto.example.com/ in this case).

Step 2: Developing time!

In order to hot-reload your application in your remote development environment, run the this command:

$ okteto up vote
 i  Using cindy @ okteto.example.com as context
i Development environment 'compose-getting-started' already deployed.
i To redeploy your development environment run 'okteto deploy' or 'okteto up vote --deploy'
✓ Persistent volume successfully attached
✓ Images successfully pulled
✓ Files synchronized
Context: okteto.example.com
Namespace: cindy
Name: vote
Forward: 8080 -> 8080

* Serving Flask app 'app' (lazy loading)
* Environment: development
* Debug mode: on
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://10.8.35.69:8080/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 838-277-059

From this moment, all you code changes will be immediately synched and hot-reloaded by your development environment. For example, open the vote/app.py file in your IDE and modify the voting options on lines 16-17.

def getOptions():
option_a = "Local development"
option_b = "Cloud development"

Save your changes. Check the output of your development environment:

 * Detected change in '/src/app.py', reloading
* Restarting with stat
* Debugger is active!
* Debugger PIN: 838-277-059

Access the URL of your application again. Your code changes were instantly applied. No commit, build, or push required!

Next steps

Congratulations, you just developed your first application with Okteto 🚀.

Read the docs for the Docker Compose and the available Okteto CLI commands to learn more about developing your Docker Compose application on Okteto.

Head over to our getting started guides to see how to configure Okteto to live-update your application with different programming languages and debuggers.