|
| 1 | ++++ |
| 2 | +title="Building on Podman" |
| 3 | +weight=99 |
| 4 | +summary="Use podman as an alternative to Docker with Cloud Native Buildpacks." |
| 5 | +aliases=[ |
| 6 | + "/docs/using-pack/building-app/" |
| 7 | +] |
| 8 | ++++ |
| 9 | + |
| 10 | +### What is Podman? |
| 11 | + |
| 12 | +To quote from the official documentation: |
| 13 | + |
| 14 | +> Podman is a daemonless, open source, Linux native tool designed to make it easy to find, run, build, share and deploy applications using Open Containers Initiative (OCI) Containers and Container Images. |
| 15 | +
|
| 16 | +It can be used as a standalone daemonless CLI with sub-commands and flags almost identical the standard `docker` CLI. You can even alias `docker=podman` and everything should work as expected. |
| 17 | + |
| 18 | +Beside running as a standalone daemonless CLI, `podman` can also serve as a `docker` API daemon using `podman system service` sub-command. You just need to set the `DOCKER_HOST` environment and most applications will pick it up (`pack` is one of them). |
| 19 | + |
| 20 | +While `podman` is native to Linux you still can enjoy it on `macOS` using virtual machine. There is sub-command `podman machine` facilitating VM creation making it really easy. |
| 21 | + |
| 22 | +# Setup |
| 23 | + |
| 24 | +Minimal required versions: |
| 25 | + |
| 26 | + * `podman v3.3.0` or newer |
| 27 | + * [`pack v0.22.0`](/docs/tools/pack/) or newer |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +{{< podman-setup >}} |
| 32 | + |
| 33 | +# Usage |
| 34 | + |
| 35 | +## Build |
| 36 | + |
| 37 | +### Source |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +```shell=bash |
| 42 | +git clone https://github.com/buildpacks/samples |
| 43 | +``` |
| 44 | + |
| 45 | +### `pack build` |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +```shell=bash |
| 50 | +pack build sample-app -p samples/apps/ruby-bundler/ -B cnbs/sample-builder:bionic |
| 51 | +``` |
| 52 | + |
| 53 | +Where: |
| 54 | + - `sample-app` is the image name of the image to be created. |
| 55 | + - `-p` is the **path** to the application source. |
| 56 | + - `-B` is the **[builder][builder]** to use. |
| 57 | + |
| 58 | +> **NOTE**: If using a _socket_ connection, for example on Linux, you'll need to pass an additional flag in order to provide the proper socket location to the `lifecycle`: `--docker-host=inherit` |
| 59 | +> <br/><br/> |
| 60 | +> In the future, this may be [automatically detected](https://github.com/buildpacks/pack/issues/1338). |
| 61 | +
|
| 62 | +### Results |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +```shell=bash |
| 67 | +podman images |
| 68 | +``` |
| 69 | + |
| 70 | +[builder]: https://buildpacks.io/docs/concepts/components/builder/ |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +# Known Issues & Limitations |
| 75 | + |
| 76 | + * On `macOS` bind mounts do not work since the VM cannot access host file system. |
| 77 | + * With more time consuming builds and `--trust-builder=true` following error may occur: |
| 78 | + ``` |
| 79 | + ERROR: failed to image: error during connect: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.40/info": EOF |
| 80 | + ``` |
| 81 | + There is a workaround for this, increase timeout of podman service: |
| 82 | + ```shell=bash |
| 83 | + cat <<EOF > /etc/systemd/user/podman.service |
| 84 | + [Unit] |
| 85 | + Description=Podman API Service |
| 86 | + Requires=podman.socket |
| 87 | + After=podman.socket |
| 88 | + Documentation=man:podman-system-service(1) |
| 89 | + StartLimitIntervalSec=0 |
| 90 | +
|
| 91 | + [Service] |
| 92 | + Type=exec |
| 93 | + KillMode=process |
| 94 | + Environment=LOGGING="--log-level=info" |
| 95 | + ExecStart=/usr/bin/podman $LOGGING system service --time=1800 |
| 96 | +
|
| 97 | + [Install] |
| 98 | + WantedBy=multi-user.target |
| 99 | + EOF |
| 100 | + |
| 101 | + systemctl --user daemon-reload |
| 102 | + systemctl restart --user podman.socket |
| 103 | + ``` |
| 104 | +
|
| 105 | + On `macOS` you need to run this in the VM (use `podman machine ssh`). |
0 commit comments