github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/Documentation/subcommands/run.md (about)

     1  # rkt run
     2  
     3  ## Image Addressing
     4  
     5  Images can be run by either their name, their hash, an explicit transport address, or a Docker registry URL.
     6  rkt will automatically [fetch][fetch] them if they're not present in the local store.
     7  
     8  ### Run By Name
     9  ```
    10  # rkt run coreos.com/etcd:v2.0.0
    11  ```
    12  
    13  ### Run By Hash
    14  ```
    15  # rkt run sha512-fa1cb92dc276b0f9bedf87981e61ecde
    16  ```
    17  
    18  ### Run By ACI Address
    19  ```
    20  # rkt run https://github.com/coreos/etcd/releases/download/v2.0.0/etcd-v2.0.0-linux-amd64.aci
    21  ```
    22  
    23  ### Run From a Docker Registry
    24  ```
    25  # rkt --insecure-options=image run docker://quay.io/coreos/etcd:v2.0.0
    26  ```
    27  
    28  ## Run multiple applications in the same pod
    29  
    30  Multiple applications can be run in a pod by passing multiple images to the run command:
    31  ```
    32  # rkt run example.com/app1 example.com/app2
    33  ```
    34  
    35  ## Run from a runtime manifest
    36  
    37  The flag `--pod-manifest` allows users to specify a [*runtime manifest*](https://github.com/appc/spec/blob/master/spec/pods.md#app-container-pods-pods)
    38  to run as a pod. This means image manifests for apps in the pod will be
    39  overriden and any configuration specified in them will be ignored.
    40  
    41  For more details about generating a *runtime manifest*, check the [pod manifest walkthrough][pod-manifest-walkthrough].
    42  
    43  ## Overriding the app's name
    44  
    45  Be default, the image's name will be used as the app's name.
    46  It can be overridden by rkt using the `--name` flag.
    47  This comes handy when we want to run multiple apps using the same image:
    48  
    49  ```
    50  # rkt --insecure-options=image run docker://busybox --name=busybox1 docker://busybox --name=busybox2
    51  ```
    52  
    53  ## Overriding Executable to launch
    54  
    55  Application images include an `exec` field that specifies the executable to launch.
    56  This executable can be overridden by rkt using the `--exec` flag:
    57  
    58  ```
    59  # rkt --insecure-options=image run docker://busybox --exec /bin/date
    60  ```
    61  
    62  ## Overriding Isolators
    63  
    64  Application images can include per-app isolators and some of them can be overridden by rkt.
    65  The units come from [the Kubernetes resource model][k8s-resources].
    66  In the following example, the CPU isolator is defined to 750 milli-cores and the memory isolator limits the memory usage to 128MB.
    67  
    68  ```
    69  # rkt run coreos.com/etcd:v2.0.0 --cpu=750m --memory=128M
    70  ```
    71  
    72  ## Overriding User/Group
    73  
    74  Application images must specify the username/group or the UID/GID the app is to be run as as specified in the [Image Manifest Schema][image-manifest-schema]. The user/group can be overridden by rkt using the `--user` and `--group` flags:
    75  
    76  ```
    77  # rkt --insecure-options=image run docker://busybox --user=1000 --group=100 --exec id
    78  ```
    79  
    80  ## Passing Arguments
    81  
    82  To pass additional arguments to images use the pattern of `image1 -- [image1 flags] --- image2 -- [image2 flags]`.
    83  For example:
    84  
    85  ```
    86  # rkt run example.com/worker -- --loglevel verbose --- example.com/syncer -- --interval 30s
    87  ```
    88  
    89  This can be combined with overridden executables:
    90  
    91  ```
    92  # rkt run example.com/worker --exec /bin/ov -- --loglevel verbose --- example.com/syncer --exec /bin/syncer2 -- --interval 30s
    93  ```
    94  
    95  ## Adding user annotations and user labels
    96  
    97  Additional annotations and labels can be added to the app by using `--user-annotation` and `--user-label` flag.
    98  The annotations and labels will appear in the app's `UserAnnotations` and `UserLabels` field.
    99  
   100  ```
   101  # rkt run example.com/example --user-annotation=foo=bar --user-label=hello=world
   102  ```
   103  
   104  ## Influencing Environment Variables
   105  
   106  To inherit all environment variables from the parent, use the `--inherit-env` flag.
   107  
   108  To explicitly set environment variables for all apps, use the `--set-env` flag.
   109  
   110  To explicitly set environment variables for all apps from a file, use the `--set-env-file` flag.
   111  Variables are expected to be in the format `VAR_NAME=VALUE` separated by the new line character `\n`.
   112  Lines starting with `#` or `;` and empty ones will be ignored.
   113  
   114  To explicitly set environment variables for each app individually, use the `--environment` flag.
   115  
   116  The precedence is as follows with the last item replacing previous environment entries:
   117  
   118  - Parent environment
   119  - App image environment
   120  - Explicitly set environment variables for all apps from file (`--set-env-file`)
   121  - Explicitly set environment variables for all apps on command line (`--set-env`)
   122  - Explicitly set environment variables for each app on command line (`--environment`)
   123  
   124  ```
   125  # export EXAMPLE_ENV=hello
   126  # export EXAMPLE_OVERRIDE=under
   127  # rkt run --inherit-env --set-env=FOO=bar --set-env=EXAMPLE_OVERRIDE=over example.com/env-printer
   128  EXAMPLE_ENV=hello
   129  FOO=bar
   130  EXAMPLE_OVERRIDE=over
   131  
   132  # export EXAMPLE_ENV=hello
   133  # export EXAMPLE_OVERRIDE=under
   134  # rkt run --inherit-env --set-env=FOO=bar --set-env=EXAMPLE_OVERRIDE=over example.com/env-printer --environment=EXAMPLE_OVERRIDE=ride
   135  EXAMPLE_ENV=hello
   136  FOO=bar
   137  EXAMPLE_OVERRIDE=ride
   138  ```
   139  
   140  ## Disable Signature Verification
   141  
   142  If desired, `--insecure-options=image` can be used to disable this security check:
   143  
   144  ```
   145  # rkt --insecure-options=image run coreos.com/etcd:v2.0.0
   146  rkt: searching for app image coreos.com/etcd:v2.0.0
   147  rkt: fetching image from https://github.com/coreos/etcd/releases/download/v2.0.0/etcd-v2.0.0-linux-amd64.aci
   148  rkt: warning: signature verification has been disabled
   149  ...
   150  ```
   151  
   152  ## Mount Volumes into a Pod
   153  
   154  Each ACI can define a [list of mount points][image-manifest-schema] that the app is expecting external data to be mounted into:
   155  
   156  ```json
   157  {
   158      "acKind": "ImageManifest",
   159      "name": "example.com/app1",
   160      ...
   161      "app": {
   162          ...
   163          "mountPoints": [
   164              {
   165                  "name": "data",
   166                  "path": "/var/data",
   167                  "readOnly": false,
   168                  "recursive": true
   169              }
   170          ]
   171      }
   172      ...
   173  }
   174  ```
   175  
   176  To fulfill these mount points, volumes are used.
   177  A volume is assigned to a mount point if they both have the same name.
   178  There are today two kinds of volumes:
   179  
   180  - `host` volumes that can expose a directory or a file from the host to the pod.
   181  - `empty` volumes that initialize an empty storage to be accessed locally within the pod. When the pod is garbage collected, it will be removed.
   182  
   183  Each volume can be selectively mounted into each application at differing mount points.
   184  Note that any volumes that are specified but do not have a matching mount point (or [`--mount` flag](#mounting-volumes-without-mount-points)) will be silently ignored.
   185  
   186  If a mount point is specified in the image manifest but no matching volume is found, an implicit `empty` volume will be created automatically.
   187  
   188  ### Mounting Volumes
   189  
   190  Volumes are defined via the `--volume` flag, the volume is then mounted into each app running in the pod based on information defined in the ACI manifest.
   191  
   192  There are two kinds of volumes, `host` and `empty`.
   193  
   194  #### Host Volumes
   195  
   196  For `host` volumes, the `--volume` flag allows you to specify the volume name, the location on the host, whether the volume is read-only or not, and whether the volume is recursive or not.
   197  The volume name and location on the host are mandatory.
   198  The read-only parameter is false by default.
   199  The recursive parameter is true by default for the coreos and KVM stage1 flavors, and false by default for the fly stage1 flavor.
   200  
   201  Syntax:
   202  
   203  ```
   204  --volume NAME,kind=host,source=SOURCE_PATH,readOnly=BOOL,recursive=BOOL
   205  ```
   206  
   207  In the following example, we make the host's `/srv/data` accessible to app1 on `/var/data`:
   208  
   209  ```
   210  # rkt run --volume data,kind=host,source=/srv/data,readOnly=false example.com/app1
   211  ```
   212  
   213  Here we set the recursive option to false to avoid making further mounts inside `/srv/data` available to the container:
   214  
   215  ```
   216  # rkt run --volume data,kind=host,source=/srv/data,readOnly=false,recursive=false example.com/app1
   217  ```
   218  
   219  #### Host Devices
   220  
   221  Using devices from the host inside the container in rkt works by just creating volumes with the source set to the particular device.
   222  You can find some examples in the [block devices documentation](../block-devices.md).
   223  
   224  #### Empty Volumes
   225  
   226  If you don't intend to persist the data and you just want to have a volume shared between all the apps in the pod, you can use an `empty` volume:
   227  
   228  ```
   229  # rkt run --volume data,kind=empty,readOnly=false example.com/app1
   230  ```
   231  
   232  For `empty` volumes, the `--volume` flag allows you to specify the volume name, and the mode, UID and GID of the generated volume.
   233  The volume name is mandatory.
   234  By default, `mode` is `0755`, UID is `0` and GID is `0`.
   235  
   236  Syntax:
   237  
   238   `--volume NAME,kind=empty,mode=MODE,uid=UID,gid=GID`
   239  
   240   In the following example, we create an empty volume for app1's `/var/data`:
   241  
   242   ```
   243   # rkt run --volume data,kind=empty,mode=0700,uid=0,gid=0
   244   ```
   245  
   246  ### Mounting Volumes without Mount Points
   247  
   248  If the ACI doesn't have any mount points defined in its manifest, you can still mount volumes using the `--mount` flag.
   249  
   250  With `--mount` you define a mapping between volumes and a path in the app.
   251  This will supplement and override any mount points in the image manifest.
   252  In the following example, the `--mount` option is positioned after the app name; it defines the mount only in that app:
   253  
   254  ```
   255  # rkt run --volume logs,kind=host,source=/srv/logs \
   256          example.com/app1 --mount volume=logs,target=/var/log \
   257          example.com/app2 --mount volume=logs,target=/opt/log
   258  ```
   259  
   260  In the following example, the `--mount` option is positioned before the app names.
   261  It defines mounts on all apps: both app1 and app2 will have `/srv/logs` accessible on `/var/log`.
   262  
   263  ```
   264  # rkt run --volume logs,kind=host,source=/srv/logs \
   265         --mount volume=data,target=/var/log \
   266          example.com/app1 example.com/app2
   267  ```
   268  
   269  ### MapReduce Example
   270  
   271  Let's say we want to read data from the host directory `/opt/tenant1/work` to power a MapReduce-style worker.
   272  We'll call this app `example.com/reduce-worker`.
   273  
   274  We also want this data to be available to a backup application that runs alongside the worker (in the same pod).
   275  We'll call this app `example.com/worker-backup`.
   276  The backup application only needs read-only access to the data.
   277  
   278  Below we show the abbreviated manifests for the respective applications (recall that the manifest is bundled into the application's ACI):
   279  
   280  ```json
   281  {
   282      "acKind": "ImageManifest",
   283      "name": "example.com/reduce-worker",
   284      ...
   285      "app": {
   286          ...
   287          "mountPoints": [
   288              {
   289                  "name": "work",
   290                  "path": "/var/lib/work",
   291                  "readOnly": false
   292              }
   293          ],
   294          ...
   295      }
   296      ...
   297  }
   298  ```
   299  
   300  ```json
   301  {
   302      "acKind": "ImageManifest",
   303      "name": "example.com/worker-backup",
   304      ...
   305      "app": {
   306          ...
   307          "mountPoints": [
   308              {
   309                  "name": "work",
   310                  "path": "/backup",
   311                  "readOnly": true
   312              }
   313          ],
   314          ...
   315      }
   316      ...
   317  }
   318  ```
   319  
   320  In this case, both apps reference a volume they call "work", and expect it to be made available at `/var/lib/work` and `/backup` within their respective root filesystems.
   321  
   322  Since they reference the volume using an abstract name rather than a specific source path, the same image can be used on a variety of different hosts without being coupled to the host's filesystem layout.
   323  
   324  To tie it all together, we use the `rkt run` command-line to provide them with a volume by this name. Here's what it looks like:
   325  
   326  ```
   327  # rkt run --volume=work,kind=host,source=/opt/tenant1/work \
   328    example.com/reduce-worker \
   329    example.com/worker-backup
   330  ```
   331  
   332  If the image didn't have any mount points, you can achieve a similar effect with the `--mount` flag (note that both would be read-write though):
   333  
   334  ```
   335  # rkt run --volume=work,kind=host,source=/opt/tenant1/work \
   336    example.com/reduce-worker --mount volume=work,target=/var/lib/work \
   337    example.com/worker-backup --mount volume=work,target=/backup
   338  ```
   339  
   340  Now when the pod is running, the two apps will see the host's `/opt/tenant1/work` directory made available at their expected locations.
   341  
   342  ## Enabling metadata service registration
   343  
   344  By default, `rkt run` will not register the pod with the [metadata service][metadata-service].
   345  You can enable registration with the `--mds-register` command line option.
   346  
   347  ## Pod Networking
   348  
   349  The `run` subcommand features the `--net` argument which takes options to configure the pod's network.
   350  
   351  ### Default contained networking
   352  
   353  When the argument is not given, `--net=default` is automatically assumed and the default contained network will be loaded.
   354  
   355  ### Host networking
   356  
   357  Simplified, with `--net=host` the apps within the pod will share the network stack and the interfaces with the host machine.
   358  
   359  ```
   360  # rkt run --net=host coreos.com/etcd:v2.0.0
   361  ```
   362  
   363  Strictly seen, this is only true when `rkt run` is invoked on the host directly, because the network stack will be inherited from the process that is invoking the `rkt run` command.
   364  
   365  ### Other Networking Examples
   366  
   367  More details about rkt's networking options and examples can be found in the [networking documentation][net-overview].
   368  
   369  ## Run rkt as a Daemon
   370  
   371  rkt doesn't include any built-in support for running as a daemon.
   372  However, since it is a regular process, you can use your init system to achieve the same effect.
   373  
   374  For example, if you use systemd, you can [run rkt using `systemd-run`][systemd-run].
   375  
   376  If you don't use systemd, you can use [daemon][daemon] as an alternative.
   377  
   378  ## Use a Custom Stage1
   379  
   380  rkt is designed and intended to be modular, using a [staged architecture][rkt-arch].
   381  
   382  You can use a custom stage1 by using the `--stage1-{url,path,name,hash,from-dir}` flags.
   383  
   384  ```
   385  # rkt --stage1-path=/tmp/stage1.aci run coreos.com/etcd:v2.0.0
   386  ```
   387  
   388  rkt expects stage1 images to be signed except in the following cases:
   389  
   390  * it is the default stage1 image and it's in the same directory as the rkt binary
   391  * `--stage1-{name,hash}` is used and the image is already in the store
   392  * `--stage1-{url,path,from-dir}` is used and the image is in the default directory configured at build time
   393  
   394  For more details see the [hacking documentation][rkt-hacking].
   395  
   396  ## Disabling overlay
   397  
   398  rkt uses overlayfs by default when running application containers. This provides immense benefits to performance and efficiency: start times for large containers are much faster, and multiple pods using the same images will consume less disk space and can share page cache entries.
   399  
   400  This feature will be disabled automatically if the underlying filesystem does not support overlay fs, see the [prepare][prepare] subcommand for details. This feature can also be explicitly disabled with the `--no-overlay` option:
   401  
   402  ```
   403  # rkt run --no-overlay=true --insecure-options=image coreos.com/etcd:v2.0.0
   404  ```
   405  
   406  ## Options
   407  
   408  | Flag | Default | Options | Description |
   409  | --- | --- | --- | --- |
   410  | `--caps-remove` | none | capability to remove (e.g. `--caps-remove=CAP_SYS_CHROOT,CAP_MKNOD`) | Capabilities to remove from the process's capabilities bounding set; all others from the default set will be included. |
   411  | `--caps-retain` | none | capability to retain (e.g. `--caps-retain=CAP_SYS_ADMIN,CAP_NET_ADMIN`) | Capabilities to retain in the process's capabilities bounding set; all others will be removed. |
   412  | `--cpu` | none | CPU units (e.g. `--cpu=500m`) | CPU limit for the preceding image in [Kubernetes resource model][k8s-resources] format. |
   413  | `--dns` | none | IP Addresses (separated by comma), `host`, or `none` | Name server to write in `/etc/resolv.conf`. It can be specified several times. Pass `host` only to use host's resolv.conf or `none` only to ignore CNI DNS config. |
   414  | `--dns-domain` | none | DNS domain (e.g., `--dns-domain=example.com`) | DNS domain to write in `/etc/resolv.conf`. |
   415  | `--dns-opt` | none | DNS option | DNS option from resolv.conf(5) to write in `/etc/resolv.conf`. It can be specified several times. |
   416  | `--dns-search` | none | Domain name | DNS search domain to write in `/etc/resolv.conf`. It can be specified several times. |
   417  | `--environment` | none | environment variables add to the app's environment variables | Set the app's environment variables (example: '--environment=foo=bar'). |
   418  | `--exec` | none | Path to executable | Override the exec command for the preceding image. |
   419  | `--group` | root | gid, groupname or file path (e.g. `--group=core`) | Group override for the preceding image. |
   420  | `--hosts-entry` | none | an /etc/hosts entry within the container (e.g., `--hosts-entry=10.2.1.42=db`) | Entries to add to the pod-wide /etc/hosts. Pass 'host' to use the host's /etc/hosts. |
   421  | `--hostname` | `rkt-$PODUUID` | A host name | Set pod's host name. |
   422  | `--inherit-env` | `false` | `true` or `false` | Inherit all environment variables not set by apps. |
   423  | `--interactive` | `false` | `true` or `false` | Run pod interactively. If true, only one image may be supplied. |
   424  | `--ipc` | `auto` | `auto`, `private` or `parent` | Whether to stay in the host IPC namespace. |
   425  | `--mds-register` | `false` | `true` or `false` | Register pod with metadata service. It needs network connectivity to the host (`--net` as `default`, `default-restricted`, or `host`). |
   426  | `--memory` | none | Memory units (e.g. `--memory=50M`) | Memory limit for the preceding image in [Kubernetes resource model][k8s-resources] format. |
   427  | `--mount` | none | Mount syntax (e.g. `--mount volume=NAME,target=PATH`) | Mount point binding a volume to a path within an app. See [Mounting Volumes without Mount Points](#mounting-volumes-without-mount-points). |
   428  | `--name` | none | Name of the app | Set the name of the app (example: '--name=foo'). If not set, then the app name default to the image's name |
   429  | `--net` | `default` | A comma-separated list of networks. (e.g. `--net[=n[:args], ...]`) | Configure the pod's networking. Optionally, pass a list of user-configured networks to load and set arguments to pass to each network, respectively. |
   430  | `--no-overlay` | `false` | `true` or `false` | Disable the overlay filesystem. |
   431  | `--oom-score-adjust` | none | adjust /proc/$pid/oom_score_adj  | oom-score-adj isolator override. |
   432  | `--pod-manifest` | none | A path | The path to the pod manifest. If it's non-empty, then only `--net`, `--no-overlay` and `--interactive` will have effect. |
   433  | `--port` | none | A port name and number pair | Container port name to expose through host port number. Requires [contained network][contained]. Syntax: `--port=NAME:HOSTPORT` The NAME is that given in the ACI. By convention, Docker containers' EXPOSEd ports are given a name formed from the port number, a hyphen, and the protocol, e.g., `80-tcp`, giving something like `--port=80-tcp:8080`. |
   434  | `--private-users` | `false` | `true` or `false` | Run within user namespaces. |
   435  | `--pull-policy` | `new` | `never`, `new`, or `update` | Sets the policy for when to fetch an image. See [image fetching behavior][img-fetch] |
   436  | `--readonly-rootfs` | none | set root filesystem readonly (e.g., `--readonly-rootfs=true`) | if set, the app's rootfs will be mounted read-only |
   437  | `--seccomp` | none | filter override (e.g., `--seccomp mode=retain,errno=EPERM,chmod,chown`) | seccomp filter override |
   438  | `--set-env` | none | An environment variable (e.g. `--set-env=NAME=VALUE`) | An environment variable to set for apps. |
   439  | `--set-env-file` | none | Path of an environment variables file (e.g. `--set-env-file=/path/to/env/file`) | Environment variables to set for apps. |
   440  | `--signature` | none | A file path | Local signature file to use in validating the preceding image. |
   441  | `--stage1-from-dir` | none | Image name (e.g. `--stage1-name=coreos.com/rkt/stage1-coreos`) | A stage1 image file name to search for inside the default stage1 images directory. |
   442  | `--stage1-hash` | none | Image hash (e.g. `--stage1-hash=sha512-dedce9f5ea50`) | A hash of a stage1 image. The image must exist in the store. |
   443  | `--stage1-name` | none | Image name (e.g. `--stage1-name=coreos.com/rkt/stage1-coreos`) | A name of a stage1 image. Will perform a discovery if the image is not in the store. |
   444  | `--stage1-path` | none | Absolute or relative path | A path to a stage1 image. |
   445  | `--stage1-url` | none | URL with protocol | A URL to a stage1 image. HTTP/HTTPS/File/Docker URLs are supported. |
   446  | `--supplementary-gids` | none | supplementary group IDs (e.g., `--supplementary-gids=1024,2048`) | supplementary group IDs override for the preceding image |
   447  | `--user` | none | uid, username or file path (e.g. `--user=core`) | User override for the preceding image. |
   448  | `--user-annotation` | none | annotation add to the app's UserAnnotations field | Set the app's annotations (example: '--user-annotation=foo=bar'). |
   449  | `--user-label` | none | label add to the apps' UserLabels field | Set the app's labels (example: '--user-label=foo=bar'). |
   450  | `--uuid-file-save` | none | A file path | Write out the pod UUID to a file. |
   451  | `--volume` | none | Volume syntax (e.g. `--volume NAME,kind=KIND,source=PATH,readOnly=BOOL`) | Volumes to make available in the pod. See [Mount Volumes into a Pod](#mount-volumes-into-a-pod). |
   452  | `--working-dir` | none | working directory override (e.g. `--working-dir=/tmp/bar`) | Override the working directory in the preceding image. |
   453  
   454  ## Per-application options
   455  
   456  | Flag | Default | Options | Description |
   457  | ---  | ---     | ---     | ---         |
   458  | `--stdin`  | "null" | "null", "tty", "stream"        | Mode for this application stdin.  |
   459  | `--stdout` | "log"  | "null", "tty", "stream", "log" | Mode for this application stdout. |
   460  | `--stderr` | "log"  | "null", "tty", "stream", "log" | Mode for this application stderr. |
   461  
   462  ## Global options
   463  
   464  See the table with [global options in general commands documentation][global-options].
   465  
   466  
   467  [contained]: ../networking/overview.md#contained-mode
   468  [daemon]: http://www.libslack.org/daemon/
   469  [fetch]: fetch.md
   470  [global-options]: ../commands.md#global-options
   471  [image-manifest-schema]: https://github.com/appc/spec/blob/master/spec/aci.md#image-manifest-schema
   472  [img-fetch]: ../image-fetching-behavior.md
   473  [k8s-resources]: https://github.com/kubernetes/kubernetes/blob/release-1.2/docs/design/resources.md
   474  [metadata-service]: metadata-service.md
   475  [net-overview]: ../networking/overview.md
   476  [prepare]: prepare.md
   477  [rkt-arch]: ../devel/architecture.md
   478  [rkt-hacking]: ../hacking.md
   479  [systemd-run]: ../using-rkt-with-systemd.md#systemd-run
   480  [pod-manifest-walkthrough]: ../pod-manifest.md