Skip to main content

Container

The sim.Container resource allows running containers in the Wing Simulator:

bring sim;
bring http;

let c = new sim.Container(
name: "http-echo",
image: "hashicorp/http-echo",
containerPort: 5678,
args: ["-text=bang"],
);

test "send request" {
http.get("http://localhost:{c.hostPort}");
}

There is also support for building containers from a local directory with a Dockerfile:

new sim.Container(
name: "my-service",
image: "./my-service",
containerPort: 8080,
);

Retaining state

When the Wing Console is closed, all containers are stopped and removed. To retain the state of a container across console restarts, you can mount an anonymous volume:

new sim.Container(
name: "my-service",
image: "./my-service",
containerPort: 8080,
volumes: ["/var/data"],
);

Wing will automatically name each unnamed volume in volumes, and reuse the named volumes across console restarts.

API

  • name - a name for the container.
  • image - a name of a public Docker image to pull and run or a path to a local directory with a Dockerfile.
  • containerPort - a TCP port to expose from the container (optional).
  • env - environment variables to set in the container.
  • args - container entrypoint arguments
  • sourcePattern - a glob pattern to use to match the files for calculating the source hash when determining if a rebuild is needed. By default this is all the files in the docker build context directory (and below).
  • sourceHash - An explicit source hash that represents the container source. if not set, and sourcePattern is set, the hash will be calculated based on the content of the source files.

API Reference

Resources

Container

Represents a container running in the Wing Simulator.

Initializers

bring sim;

new sim.Container(props: ContainerProps);
NameTypeDescription
props
ContainerProps
No description.

propsRequired

Methods

Preflight Methods
NameDescription
toSimulator
Convert this resource to a resource schema for the simulator.

toSimulator
toSimulator(): ToSimulatorOutput

Convert this resource to a resource schema for the simulator.

Static Functions

NameDescription
onLiftType
A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.
toInflight
Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource.

onLiftType
bring sim;

sim.Container.onLiftType(host: IInflightHost, ops: MutArray<str>);

A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.

The list of requested inflight methods needed by the inflight host are given by ops.

This method is commonly used for adding permissions, environment variables, or other capabilities to the inflight host.

hostRequired

opsRequired
  • Type: MutArray<str>

toInflight
bring sim;

sim.Container.toInflight(obj: IResource);

Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource.

NOTE: This statement must be executed within an async context.

objRequired

Properties

NameTypeDescription
node
constructs.NodeThe tree node.
hostPort
strA token that resolves to the host port of this container.

nodeRequired
node: Node;
  • Type: constructs.Node

The tree node.


hostPortOptional
hostPort: str;
  • Type: str

A token that resolves to the host port of this container.


Structs

ContainerProps

Initialization properties for sim.Container.

Initializer

bring sim;

let ContainerProps = sim.ContainerProps{ ... };

Properties

NameTypeDescription
image
strA name of a public Docker image to pull and run or a path to a local directory with a Dockerfile.
name
strA name for the container.
args
MutArray<str>Container arguments.
containerPort
numInternal container port to expose.
entrypoint
strContainer entrypoint.
env
MutMap<str>Environment variables to set in the container.
network
strDocker network to use for the container - such as 'host', 'bridge', etc.
sourceHash
strAn explicit source hash that represents the container source.
sourcePattern
strA glob of local files to consider as input sources for the container, relative to the build context directory.
volumes
MutArray<str>Volume mount points.

imageRequired
image: str;
  • Type: str

A name of a public Docker image to pull and run or a path to a local directory with a Dockerfile.


nameRequired
name: str;
  • Type: str

A name for the container.


argsOptional
args: MutArray<str>;
  • Type: MutArray<str>
  • Default: []

Container arguments.


containerPortOptional
containerPort: num;
  • Type: num
  • Default: no port exposed

Internal container port to expose.


entrypointOptional
entrypoint: str;
  • Type: str
  • Default: default image entrypoint

Container entrypoint.


envOptional
env: MutMap<str>;
  • Type: MutMap<str>
  • Default: {}

Environment variables to set in the container.


networkOptional
network: str;
  • Type: str
  • Default: default docker network

Docker network to use for the container - such as 'host', 'bridge', etc.

https://docs.docker.com/network.


Example

'host'
sourceHashOptional
sourceHash: str;
  • Type: str
  • Default: calculated based on the source files

An explicit source hash that represents the container source.

if not set, and sourcePattern is set, the hash will be calculated based on the content of the source files.


sourcePatternOptional
sourcePattern: str;
  • Type: str
  • Default: all files

A glob of local files to consider as input sources for the container, relative to the build context directory.


volumesOptional
volumes: MutArray<str>;
  • Type: MutArray<str>
  • Default: []

Volume mount points.


Example

['/host:/container']