Skip to contents

Adds an EXPOSE instruction to inform Docker that the container will listen on the specified network ports at runtime.

Usage

dfi_expose(dockerfile, ports)

Arguments

dockerfile

A dockerfile object

ports

Ports to expose (numeric or character vector)

Value

An updated dockerfile object with the EXPOSE instruction added

Details

The EXPOSE instruction does not actually publish the port. It functions as documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published.

To actually publish the port when running the container, use the -p flag in the docker run command.

See also

dk_template_shiny() for a template that exposes Shiny ports, dk_template_plumber() for a template that exposes Plumber API ports, & Official Docker EXPOSE documentation

Other dockerfile instruction functions: dfi_add(), dfi_arg(), dfi_cmd(), dfi_copy(), dfi_entrypoint(), dfi_env(), dfi_from(), dfi_healthcheck(), dfi_label(), dfi_maintainer(), dfi_onbuild(), dfi_run(), dfi_shell(), dfi_stopsignal(), dfi_user(), dfi_volume(), dfi_workdir()

Examples

# Expose a single port
df <- dockerfile() |>
  dfi_from("rocker/r-ver:4.4.0") |>
  dfi_expose(8080)
  
# Expose multiple ports
df <- dockerfile() |>
  dfi_from("rocker/shiny:4.4.0") |>
  dfi_expose(c(3838, 8080))