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 aDockerfile
.containerPort
- a TCP port to expose from the container (optional).env
- environment variables to set in the container.args
- container entrypoint argumentssourcePattern
- 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, andsourcePattern
is set, the hash will be calculated based on the content of the source files.
API Reference
Resources
Container
- Implements: ISimulatorResource
Represents a container running in the Wing Simulator.
Initializers
bring sim;
new sim.Container(props: ContainerProps);
Name | Type | Description |
---|---|---|
|
| No description. |
props
Required
- Type: ContainerProps
Methods
Preflight Methods
Name | Description |
---|---|
| 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
Name | Description |
---|---|
| A hook called by the Wing compiler once for each inflight host that needs to use this type inflight. |
| 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.
host
Required
- Type: IInflightHost
ops
Required
- 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.
obj
Required
- Type: IResource
Properties
Name | Type | Description |
---|---|---|
| constructs.Node | The tree node. |
| str | A token that resolves to the host port of this container. |
node
Required
node: Node;
- Type: constructs.Node
The tree node.
hostPort
Optional
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
Name | Type | Description |
---|---|---|
| str | A name of a public Docker image to pull and run or a path to a local directory with a Dockerfile . |
| str | A name for the container. |
| MutArray<str> | Container arguments. |
| num | Internal container port to expose. |
| str | Container entrypoint. |
| MutMap<str> | Environment variables to set in the container. |
| str | Docker network to use for the container - such as 'host', 'bridge', etc. |
| str | An explicit source hash that represents the container source. |
| str | A glob of local files to consider as input sources for the container, relative to the build context directory. |
| MutArray<str> | Volume mount points. |
image
Required
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
.
name
Required
name: str;
- Type: str
A name for the container.
args
Optional
args: MutArray<str>;
- Type: MutArray<str>
- Default: []
Container arguments.
containerPort
Optional
containerPort: num;
- Type: num
- Default: no port exposed
Internal container port to expose.
entrypoint
Optional
entrypoint: str;
- Type: str
- Default: default image entrypoint
Container entrypoint.
env
Optional
env: MutMap<str>;
- Type: MutMap<str>
- Default: {}
Environment variables to set in the container.
network
Optional
network: str;
- Type: str
- Default: default docker network
Docker network to use for the container - such as 'host', 'bridge', etc.
Example
'host'
sourceHash
Optional
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.
sourcePattern
Optional
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.
volumes
Optional
volumes: MutArray<str>;
- Type: MutArray<str>
- Default: []
Volume mount points.
Example
['/host:/container']