> ## Documentation Index
> Fetch the complete documentation index at: https://namespace.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# nsc expose container

Expose an exported port on a running container.

`expose container` opens a public ingress to an exported port on a running container. The
provided container needs to be up and running. For example, it can be started in
advance using `docker run` within an ephemeral instance. The exposed endpoint is
encrypted with TLS and secured with Namespace authentication, so whoever has
access to the workspace where the ephemeral environment was created in, will
also have access to the endpoint.

**Note**: Only HTTP services can currently be exposed.

## Usage

```bash theme={null}
nsc expose container <instance-id> --container <name> [--container_port <port[,port]>] [--ingress <rules>] [--name <ingress-name>] [--source <docker|containerd>] [--output <plain|json>]
```

### Example

In the example below we first create an ephemeral instance, then SSH into the
instance, start the nginx container with `docker run` and then expose it
using `nsc expose container`.

<Steps titleSize="h4">
  <Step title="Create an ephemeral instance">
    Create an ephemeral instance and note its ID in the output:

    ```bash theme={null}
    nsc create
    ```

    ```text nocopy Output theme={null}
    Created instance "oiepencpc41im"
     deadline: 2023-04-25T09:46:03Z
    ```
  </Step>

  <Step title="SSH into the instance">
    Connect to the instance using its ID:

    ```bash theme={null}
    nsc ssh oiepencpc41im
    ```
  </Step>

  <Step title="Start nginx container within the created instance">
    Start an nginx container that publishes port 80:

    ```bash theme={null}
    oiepencpc41im:~# docker run --name nginx-foobar -p 80:80 -d nginx
    ```
  </Step>

  <Step title="Expose the nginx container">
    Expose the container's port 80 through a public ingress:

    ```bash theme={null}
    nsc expose container oiepencpc41im --container nginx-foobar --container_port 80
    ```

    ```text nocopy Output theme={null}
    Exported port 80 from nginx-foobar (20e97bc453c936a9665dd6ce75e0168c92a689cc92214303a87fc19a):
      https://nginx-foobar-j239700-oiepencpc41im.fra1.namespaced.app
    ```
  </Step>

  <Step title="Visit the exposed endpoint">
    Open **[https://nginx-foobar-j239700-oiepencpc41im.fra1.namespaced.app](https://nginx-foobar-j239700-oiepencpc41im.fra1.namespaced.app)** in your browser and authenticate with your Namespace credentials.
  </Step>
</Steps>

## Options

<h3 id="--container-name">
  \--container \<name>
</h3>

To specify a name of a container to expose. This option is required.

<h3 id="--container_port-portport">
  \--container\_port \<port\[,port]>
</h3>

Exports the specified ports (separated by commas) as public ingresses. If the
option is not provided, all the exported ports would be exposed.

<h3 id="--ingress-rules">
  \--ingress \<rules>
</h3>

Specify additional ingress rules per exported port. The value is a mapping
from port (or `*` to apply to any port) to a semicolon-separated list of
rules, e.g. `80=rule1;rule2,443=rule3`. Each rule follows the same effect
syntax used elsewhere by `nsc expose`:

* `<effect>`: Applies effect to any method or path.
* `<path_regex>:<effect>`: Applies effect to paths that match `path_regex`
  (the full path without the query is used for matching).
* `<method>[,<method>,...]:<path_regex>:<effect>`: In addition to matching
  path, also matches against the HTTP method used.

Currently supported effect: `noauth`, which disables authentication on the
route.

<h3 id="--name-name">
  \--name \<name>
</h3>

Set the name of the exposed ingress. Setting a name is only permitted when exposing a single port.
By default, ingress names will be generated by Namespace.

<h3 id="--source-source">
  \--source \<source>
</h3>

To specify the container runtime which was used to run the container. Supported
options are `docker` and `containerd`. By default `docker` is used to lookup
running containers.

<h3 id="--output--o-plainjson">
  \--output, -o \<plain|json>
</h3>

Specifies the output format. Supported options are `json` and
`plain`. By default, plain output format is used.

<h3 id="--all">
  \--all
</h3>

Export one ingress for each exported port of each running container.

<h3 id="--wildcard">
  \--wildcard
</h3>

If set, generate a wildcard ingress for the exposed container port.
Can only be used when exposing a single port.
