Docker Compose reference
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 in Kubernetes.
Example
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!
Schema reference
services ([object], optional)
Define the services that make up your Docker Compose application.
services:
vote:
build: vote
scale: 2
ports:
- 8080:8080
redis:
image: redis
ports:
- 6379
volumes:
- redis:/data
Each service supports the fields in the Compose Specification. We summarize the most relevant ones below:
build ([string|object], optional)
Indicate how to build the image of this service when running okteto build
or okteto deploy --build
.
The value is the path to the build context:
build: vote
It can also be an object with these fields:
context
: the build context. When the value supplied is a relative path, it is interpreted as relative to the location of the Docker Compose file (default:.
)dockerfile
: the path to the Dockerfile. It is a relative path to the build context (default:Dockerfile
)target
: build the specified stage as defined inside the Dockerfile. See the multi-stage build Docker official docs for details.args
: add build arguments, which are environment variables accessible only during the build process. Build arguments with a value containing a$
sign are resolved to the environment variable value on the machine okteto is running on, which can be helpful for secret or machine-specific values.export_cache
: image tag for exported cache when build.cache_from
: list of images to import cache from.
build:
context: .
dockerfile: Dockerfile
target: prod
args:
- ENV1=prod
- ENV2=$VALUE
okteto deploy --build
builds a new docker image, pushes it to the registry and redeploys your containers.
By default, it builds the images using the Okteto Build Service. Set the variable BUILDKIT_HOST
if you want to use your own BuildKit instance.
cap_add ([string], optional)
Add container capabilities. See man 7 capabilities
for a full list.
cap_add:
- ALL
cap_drop ([string], optional)
Drop container capabilities. See man 7 capabilities
for a full list.
cap_drop:
- NET_ADMIN
- SYS_ADMIN
command (string, optional)
Override the default command of the container image CMD
.
command: --debug
command
can also be a list of strings:
command: ["-p", "3000"]
depends_on ([string]|object, optional)
Specify the conditions that the declared services must meet in order for the service to start. The condition must be one of the following:
service_started
: Wait until the service is running.service_healthy
: Wait for one of the ports of the dependent service to be available.service_completed_successfully
: Wait until the dependent service has been successfully completed.
depends_on:
app:
condition: service_started
db:
condition: service_healthy
initialization-svc:
condition: service_completed_successfully
You can also express dependencies as a list of services. In this case it will be the same as setting the condition to service_started
.
depends_on:
- app
- db
- initialization-svc
entrypoint (string, optional)
Override the default entrypoint of the container image ENTRYPOINT
.
entrypoint: yarn start
The entrypoint can also be a list of strings:
entrypoint: ["yarn", "start"]
env_file (string, optional)
Add environment variables from a file to the containers of a service. Environment variables declared in the environment section override these values. This also holds true if those values are empty or undefined.
env_file: .env
env_file
also accepts a list of files:
env_file:
- .env.frontend
- .env.api
environment ([string], optional)
Add environment variables:
environment:
DEV_MODE: yes
DB_HOST: postgres://${DB_HOST:-db}:${DB_PASSWORD}@postgres:5432/postgres
healthcheck (object, optional)
healthcheck declares a check that's run to determine whether or not containers for a service are "healthy".
start_period
(duration): Time between the start of the container and the initiation of the healthcheck.interval
(duration): Time between a healthcheck and a subsequent new try.timeout
(duration): Number of seconds after which the healthcheck times out.retries
(int): Number of retries before healthcheck fails.test
(string): Defines the command that will be run to check the container's health. It can be either a string or a list. If it's a list, the first item must be eitherNONE
,CMD
orCMD-SHELL
. If it's a string, it's equivalent to specifyingCMD-SHELL
followed by that string.http
(object): Defines the path and port that has to be tested on the container to set the healthcheck as successfulx-okteto-readiness
(bool): Defines if the probe should be a readiness probe (default:true
).x-okteto-liveness
(bool): Defines if the probe should be a liveness probe (default:false
).
healthcheck:
interval: 10s
timeout: 10m
retries: 5
start_period: 30s
http:
path: /
port: 8080
Healthchecks can also test a command as follows:
healthcheck:
interval: 10s
timeout: 10m
retries: 5
start_period: 30s
test: echo 'db.runCommand({serverStatus:1}).ok' | mongo admin -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --quiet | grep 1
image (string, optional)
The container image of each service.
image: okteto/vote:compose
If build
is defined, image
is optional. Otherwise, it's required.
labels ([string], optional)
Specify labels for the service. They translates to Kubernetes annotations.
labels:
app: sample
ports ([int], optional)
Ports exposed by each service. By default, they're only accessible from the cluster private network.
ports:
- 8080
To make the port public, use the following notation:
ports:
- 8080:8080
If you need to configure HTTPS routes, use endpoints instead of configuring an NGINX container in your Docker Compose file.
The following ports are never made public:
Protocol | Port |
---|---|
MySQL | 3306 |
OracleDB | 1521,1830 |
PostgreSQL | 5432 |
SQL Server | 1433,1434 |
MaxDB | 7210 |
Neo4j | 7473 |
ArangoDB | 8529 |
Cassandra | 7000,7001,9042 |
InfluxDB | 8086 |
Elasticsearch | 9200,9300 |
CouchDB | 5984 |
MongoDB | 27017,27018,27019,28017 |
Redis | 6379 |
Riak | 8087,8088 |
RethinkDB | 828015,29015,28015 |
Solr | 7574,8983 |
Golang debugger | 2345 |
Node debugger | 5858,9229 |
Java debugger | 5005 |
Ruby debugger | 1234 |
Python debugger | 4444,5678 |
If you need make these ports public, you can use endpoints.
scale (int, optional)
Specify the number of containers running for each service (default: 1
).
scale: 2
resources (object, optional)
Configure resource requests and limits.
resources:
requests:
cpu: 300m
memory: 500Mi
limits:
cpu: 500m
memory: 800Mi
Or with the docker-compose v3 configuration.
deploy:
resources:
reservations:
cpus: 500m
memory: 800Mi
limits:
cpus: 300m
memory: 500Mi