diff --git a/docs/features/advanced.md b/docs/features/advanced.md new file mode 100644 index 000000000..c2af420cb --- /dev/null +++ b/docs/features/advanced.md @@ -0,0 +1,42 @@ +# Advanced + +## Container Runtime Client + +Testcontainers configures an underlying container runtime to perform its tasks. This runtime works automatically with several providers like Docker, Podman, Colima, Rancher Desktop and Testcontainers Desktop. There are too many usage examples to list here, but here are some common examples: + +### Fetch container runtime information + +```js +import { getContainerRuntimeClient } from "testcontainers"; + +const containerRuntimeClient = await getContainerRuntimeClient(); + +console.log(containerRuntimeClient.info); +``` + +### Pulling an image + +```js +import { ImageName } from "testcontainers"; + +await containerRuntimeClient.image.pull(ImageName.fromString("alpine:3.12")) +``` + +### Starting a container + +```js +const container = await containerRuntimeClient.container.create({ ... }); +await containerRuntimeClient.container.start(container); +``` + +### Starting a Docker Compose environment + +```js +const environment = await containerRuntimeClient.compose.up({ ... }) +``` + +### Starting a network + +```js +const network = await containerRuntimeClient.network.create({ ... }) +``` diff --git a/mkdocs.yml b/mkdocs.yml index a1efffa85..b772f6ab2 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -40,6 +40,7 @@ nav: - Networking: features/networking.md - Compose: features/compose.md - Wait strategies: features/wait-strategies.md + - Advanced: features/advanced.md - Modules: - ArangoDB: modules/arangodb.md - Elasticsearch: modules/elasticsearch.md diff --git a/packages/testcontainers/src/index.ts b/packages/testcontainers/src/index.ts index 26851e40f..df1692b7e 100644 --- a/packages/testcontainers/src/index.ts +++ b/packages/testcontainers/src/index.ts @@ -8,6 +8,8 @@ export { export { GenericContainer } from "./generic-container/generic-container"; export { GenericContainerBuilder, BuildOptions } from "./generic-container/generic-container-builder"; export { TestContainers } from "./test-containers"; +export { ContainerRuntimeClient, getContainerRuntimeClient, ImageName } from "./container-runtime"; +export { Uuid, RandomUuid, log } from "./common"; export { DockerComposeEnvironment } from "./docker-compose-environment/docker-compose-environment"; export { StartedDockerComposeEnvironment } from "./docker-compose-environment/started-docker-compose-environment"; @@ -23,5 +25,3 @@ export { InspectResult, Content, ExecResult } from "./types"; export { AbstractStartedContainer } from "./generic-container/abstract-started-container"; export { AbstractStoppedContainer } from "./generic-container/abstract-stopped-container"; - -export { Uuid, RandomUuid, log } from "./common";