|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * serverless/cli_tools/kn-serving-ref.adoc |
| 4 | +// * serverless/knative_serving/serverless-applications.adoc |
| 5 | + |
| 6 | +[id="serverless-kn-container_{context}"] |
| 7 | += Knative client multi-container support |
| 8 | + |
| 9 | +You can use the `kn container add` command to print YAML container spec to standard output. This command is useful for multi-container use cases because it can be used along with other standard `kn` flags to create definitions. The `kn container add` command accepts all container-related flags that are supported for use with the `kn service create` command. The `kn container add` command can also be chained by using UNIX pipes (`|`) to create multiple container definitions at once. |
| 10 | + |
| 11 | +[id="serverless-kn-container-examples_{context}"] |
| 12 | +== Example commands |
| 13 | + |
| 14 | +* Add a container from an image and print it to standard output: |
| 15 | ++ |
| 16 | +[source,terminal] |
| 17 | +---- |
| 18 | +$ kn container add <container_name> --image <image_uri> |
| 19 | +---- |
| 20 | ++ |
| 21 | +.Example command |
| 22 | +[source,terminal] |
| 23 | +---- |
| 24 | +$ kn container add sidecar --image docker.io/example/sidecar |
| 25 | +---- |
| 26 | ++ |
| 27 | +.Example output |
| 28 | +[source,terminal] |
| 29 | +---- |
| 30 | +containers: |
| 31 | +- image: docker.io/example/sidecar |
| 32 | + name: sidecar |
| 33 | + resources: {} |
| 34 | +---- |
| 35 | + |
| 36 | +* Chain two `kn container add` commands together, and then pass them to a `kn service create` command to create a Knative service with two containers: |
| 37 | ++ |
| 38 | +[source,terminal] |
| 39 | +---- |
| 40 | +$ kn container add <first_container_name> --image <image_uri> | \ |
| 41 | +kn container add <second_container_name> --image <image_uri> | \ |
| 42 | +kn service create <service_name> --image <image_uri> --extra-containers - |
| 43 | +---- |
| 44 | ++ |
| 45 | +`--extra-containers -` specifies a special case where `kn` reads the pipe input instead of a YAML file. |
| 46 | ++ |
| 47 | +.Example command |
| 48 | +[source,terminal] |
| 49 | +---- |
| 50 | +$ kn container add sidecar --image docker.io/example/sidecar:first | \ |
| 51 | +kn container add second --image docker.io/example/sidecar:second | \ |
| 52 | +kn service create my-service --image docker.io/example/my-app:latest --extra-containers - |
| 53 | +---- |
| 54 | ++ |
| 55 | +The `--extra-containers` flag can also accept a path to a YAML file: |
| 56 | ++ |
| 57 | +[source,terminal] |
| 58 | +---- |
| 59 | +$ kn service create <service_name> --image <image_uri> --extra-containers <filename> |
| 60 | +---- |
| 61 | ++ |
| 62 | +.Example command |
| 63 | +[source,terminal] |
| 64 | +---- |
| 65 | +$ kn service create my-service --image docker.io/example/my-app:latest --extra-containers my-extra-containers.yaml |
| 66 | +---- |
0 commit comments