Create, update or delete Services or Volumes belonging to a Stack
PATCH/stacks/ {stackId}/
v2
PATCH
container-update-stack
This command can be used to modify the desired state of a container stack.
Usage
Obtaining the default stack
Every mStudio project comes with a default stack named default
. You can obtain the default stack by using the unknown operation container-list-stack
operation.
Creating new stacks
Creating new stacks is not supported at this time. You can only manage the default
stack.
Deleting containers/services from an existing stack
Since this is a differential PATCH
operation, omitting a service from the request body will simply leave any existing services unchanged.
Instead, to remove an existing container from a stack, set it to an empty object {}
in the request body. This will remove the container from the stack.
PATCH /v2/stacks/{stackId} HTTP/1.1
Host: api.mittwald.de
Content-Type: application/json
{
"services": {
"mysql": {}
}
}
Managing volumes
You have two options for managing storage for your container stacks:
- Explicitly declare volumes, using the
$.volumes
property of this request. Volumes are referenced by name, and can be mounted into the container by referencing them in the$.services[*].volumes
property in the format<volume-name>:<mount-path>
. - Use the project volume; this volume is shared among all managed apps and containers of a project. In order to mount the project volume, specify a file path instead of a volume name when mounting the volume (example
/home/p-XXXXX/html:/var/html
).
Request
Responses
Usage examples
- cURL
- JavaScript SDK
- PHP SDK
$ curl \
--fail \
--location \
-X PATCH \
-d '{"services":{"mysql":{"command":["mysqld"],"description":"MySQL DB","entrypoint":["docker-entrypoint.sh"],"environment":{"MYSQL_DATABASE":"my_db","MYSQL_PASSWORD":"my_password","MYSQL_ROOT_PASSWORD":"my_root_password","MYSQL_USER":"my_user"},"image":"mysql","ports":["3306:3306/tcp"],"volumes":["data:/var/lib/mysql:ro","/home/p-XXXXX/html:/var/www"]}},"volumes":{"data":{"name":"mysql-volume"}}}' \
-H "Authorization: Bearer $MITTWALD_API_TOKEN" \
-H 'Content-Type: application/json' \
https://api.mittwald.de/v2/stacks/f0f86186-0a5a-45b2-aa33-502777496347?recreate=true
import { MittwaldAPIV2Client } from "@mittwald/api-client";
import { assertStatus } from "@mittwald/api-client-commons";
const client = MittwaldAPIClient.newWithToken(process.env.MITTWALD_API_TOKEN);
const response = await client.container.updateStack({
"stackId": "f0f86186-0a5a-45b2-aa33-502777496347",
"data": {
"services": {
"mysql": {
"command": [
"mysqld"
],
"description": "MySQL DB",
"entrypoint": [
"docker-entrypoint.sh"
],
"environment": {
"MYSQL_DATABASE": "my_db",
"MYSQL_PASSWORD": "my_password",
"MYSQL_ROOT_PASSWORD": "my_root_password",
"MYSQL_USER": "my_user"
},
"image": "mysql",
"ports": [
"3306:3306/tcp"
],
"volumes": [
"data:/var/lib/mysql:ro",
"/home/p-XXXXX/html:/var/www"
]
}
},
"volumes": {
"data": {
"name": "mysql-volume"
}
}
},
"queryParameters": {
"recreate": true
}
});
assertStatus(response, 200);
use \Mittwald\ApiClient\Generated\V2\Clients\Container\UpdateStack\UpdateStackRequest;
use \Mittwald\ApiClient\Generated\V2\Clients\Container\UpdateStack\UpdateStackRequestBody;
$client = MittwaldAPIClient::newWithToken(getenv('MITTWALD_API_TOKEN'));
// TODO: Please consult the properties and constructor signature of
// UpdateStackRequestBody to learn how to construct a valid instance
$body = new UpdateStackRequestBody(/* TODO: ... */);
$request = (new UpdateStackRequest(
stackId: "f0f86186-0a5a-45b2-aa33-502777496347",
body: $body
))
->withRecreate(true);
$response = $client->container()->updateStack($request);
var_dump($response->getBody();