Skip to content

Commit 3a94c16

Browse files
authored
Dockerfile: switched to distroless, specified defaults environment variables for containerized kopia (kopia#897)
* Dockerfile: specified reasonable defaults options for containerized kopia * addressed pr comments, switched to gcr.io/distroless/static:nonroot distroless has no executable code, so this requires KOPIA_PASSWORD to always be provided via env, b/c distroless does not have /bin/stty to disable TTY echo (we should not require that, BTW) * site: added docker image documentation
1 parent 3b6cf5c commit 3a94c16

File tree

5 files changed

+67
-17
lines changed

5 files changed

+67
-17
lines changed

cli/command_repository_connect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var (
3030
func setupConnectOptions(cmd *kingpin.CmdClause) {
3131
// Set up flags shared between 'create' and 'connect'. Note that because those flags are used by both command
3232
// we must use *Var() methods, otherwise one of the commands would always get default flag values.
33-
cmd.Flag("persist-credentials", "Persist credentials").Default("true").BoolVar(&connectPersistCredentials)
33+
cmd.Flag("persist-credentials", "Persist credentials").Default("true").Envar("KOPIA_PERSIST_CREDENTIALS_ON_CONNECT").BoolVar(&connectPersistCredentials)
3434
cmd.Flag("cache-directory", "Cache directory").PlaceHolder("PATH").Envar("KOPIA_CACHE_DIRECTORY").StringVar(&connectCacheDirectory)
3535
cmd.Flag("content-cache-size-mb", "Size of local content cache").PlaceHolder("MB").Default("5000").Int64Var(&connectMaxCacheSizeMB)
3636
cmd.Flag("metadata-cache-size-mb", "Size of local metadata cache").PlaceHolder("MB").Default("5000").Int64Var(&connectMaxMetadataCacheSizeMB)

site/content/docs/Installation/_index.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ linkTitle: "Installation"
44
weight: 20
55
---
66

7-
### Installing Kopia
7+
### Installing Kopia
88

99
Kopia is an open source software (OSS) developed by a community on GitHub.
1010

1111
The recommended way of installing Kopia is to use a package manager for your operating system (YUM or APT for Linux, Homebrew for macOS, Scoop for Windows). They offer quick and convenient way of installing and keeping Kopia up-to-date. See below for more information.
1212

1313
You can also download the [Source Code](https://github.com/kopia/kopia/) or [Binary Releases](https://github.com/kopia/kopia/releases/latest) directly from GitHub.
1414

15+
Pre-built [Docker Images](#docker-images) are also available.
16+
1517
Kopia is available in two variants:
1618

1719
* `Command Line Interface (CLI)` which is a stand-alone binary called `kopia` and which can be used a terminal window or scripts. This is typically the preferred option for power users, system administrators, etc.
@@ -185,14 +187,55 @@ $ chmod u+x path/to/kopia
185187
$ sudo mv path/to/kopia /usr/local/bin/kopia
186188
```
187189

190+
### Docker Images
191+
192+
Kopia provides pre-built Docker container images for `amd64`, `arm64` and `arm` on [DockerHub](https://hub.docker.com/r/kopia/kopia).
193+
194+
The following tags are available:
195+
196+
* `latest` - tracks latest stable release
197+
* `testing` - tracks latest stable or pre-release (such as a beta or release candidate)
198+
* `unstable` - tracks latest unstable nightly build
199+
* `major.minor` - latest patch release for a given major and minor version (e.g. `0.8`)
200+
* `major.minor.patch` - specific stable release
201+
202+
In order to run Kopia in a container, you must:
203+
204+
* provide repository password via `KOPIA_PASSWORD` environment variable
205+
* mount `/app/config` directory in which Kopia will look for `repository.config` file
206+
* (recommended) mount `/app/cache` directory in which Kopia will be keeping a cache of downloaded data
207+
* (optional) mount `/app/logs` directory in which Kopia will be writing logs
208+
* mount any data directory used for locally-attached repository
209+
210+
Invocation of `kopia/kopia` in a container will be similar to the following example:
211+
212+
```shell
213+
$ docker pull kopia/kopia:testing
214+
$ docker run -e KOPIA_PASSWORD \
215+
-v /path/to/config/dir:/app/config \
216+
-v /path/to/cache/dir:/app/cache \
217+
kopia/kopia:testing snapshot list
218+
```
219+
220+
(Adjust `testing` tag to the appropriate version)
221+
222+
>NOTE Kopia in container overrides default values of some environment variables, see https://github.com/kopia/kopia/blob/master/tools/docker/Dockerfile for more details.
223+
224+
Because Docker environment uses random hostnames it is recommended to explicitly set them using `--override-hostname` and `--override-username` parameters to Kopia when connecting
225+
to a repository. The names will be persisted in a configuration file and used afterwards.
226+
188227
### Compilation From Source
189228

190-
If you have [Go 1.15](https://golang.org/) or newer, you may download and build Kopia yourself. No special setup is necessary, other than the Go compiler. You can simply run:
229+
If you have [Go 1.16](https://golang.org/) or newer, you may download and build Kopia yourself. No special setup is necessary, other than the Go compiler. You can simply run:
191230

192231
```shell
193232
$ go get github.com/kopia/kopia
194233
```
195234

196235
The resulting binary will be available in `$HOME/go/bin`. Note that this will produce basic binary that has all the features except support for HTML-based UI. To build full binary, download the source from GitHub and run:
197236

237+
```shell
238+
$ make install
239+
```
240+
198241
Additional information about building Kopia from source is available at https://github.com/kopia/kopia/blob/master/BUILD.md

tools/docker-publish.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
set -e
33
DIST_DIR=dist
44
DOCKER_BUILD_DIR=tools/docker
5-
DOCKERHUB_REPO=kopia/kopia
5+
if [ "$DOCKERHUB_REPO" == "" ]; then
6+
DOCKERHUB_REPO=kopia/kopia
7+
fi
68

79
cp -r "$DIST_DIR/kopia_linux_amd64/" "$DOCKER_BUILD_DIR/bin-amd64/"
810
cp -r "$DIST_DIR/kopia_linux_arm64/" "$DOCKER_BUILD_DIR/bin-arm64/"
@@ -41,4 +43,4 @@ for t in $extra_tags; do
4143
done
4244

4345
echo Building $versioned_image with tags [$tags]...
44-
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v6 $tags --push $DOCKER_BUILD_DIR
46+
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 $tags --push $DOCKER_BUILD_DIR

tools/docker/Dockerfile

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
FROM alpine
1+
FROM gcr.io/distroless/static:nonroot
22
ARG TARGETARCH
3-
RUN apk add --no-cache --verbose ca-certificates && adduser -D kopia && addgroup kopia kopia
4-
USER kopia:kopia
5-
ENTRYPOINT ["/kopia"]
6-
COPY bin-${TARGETARCH}/kopia /
3+
4+
# allow users to mount /app/config, /app/logs and /app/cache respectively
5+
ENV KOPIA_CONFIG_PATH=/app/config/repository.config
6+
ENV KOPIA_LOG_DIR=/app/logs
7+
ENV KOPIA_CACHE_DIRECTORY=/app/cache
8+
9+
# this requires repository password to be passed via KOPIA_PASSWORD environment.
10+
ENV KOPIA_PERSIST_CREDENTIALS_ON_CONNECT=false
11+
ENV KOPIA_CHECK_FOR_UPDATES=false
12+
13+
# this creates directories writable by the current user
14+
WORKDIR /app
15+
16+
COPY bin-${TARGETARCH}/kopia .
17+
18+
ENTRYPOINT ["/app/kopia"]

tools/docker/Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)