File: docker.md

package info (click to toggle)
trimesh 4.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 33,416 kB
  • sloc: python: 35,596; makefile: 96; javascript: 85; sh: 38
file content (67 lines) | stat: -rw-r--r-- 2,450 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Writing Docker Images
=======================

### Docker Basics

[Docker's install guide for Ubuntu.](https://docs.docker.com/desktop/install/ubuntu/)

### Using pip

Typically when writing Dockerfiles it is a good idea to use a first-party base images (i.e. `debian:buster-slim`) as derived images can sometimes be unmaintained and unknowable black boxes.

It should generally work fine to just use a first party base image and install trimesh via `pip` which always has the latest version:
```
FROM python:3.11-slim-bullseye
RUN pip install trimesh[easy]
```


### Using Prebuilt Images

The `trimesh/trimesh` docker images are based on the official Python base image, currently `python:3.11-slim-bullseye`. They are built and pushed to Docker Hub automatically in Github Actions for every release.

If you need some of the more demanding dependencies they can be a good option. The `trimesh/trimesh` images are pushed with three tags: `latest` (for latest :), semantic version (i.e. `3.15.5`), or git short hash (i.e. `1c6178d`). These images include `embree` and `trimesh[all]` which is run in a multi-stage build to avoid including intermediate files in the final image.

They run as the non-root user `user` and the working directory is `/home/user`. A minimal docker file could look like:
```
FROM trimesh/trimesh:latest

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY app.py .
CMD python app.py
```

Which you could then save as the file `Dockerfile` and build with:
```
docker build . -t example
docker run -t example
```

### Building Trimesh Images

Trimesh is using a multistage build to avoid copying in things like `g++`, so you have to explicitly specify that you want to build the `output` target. You also probably need to enable BuildKit:

```
DOCKER_BUILDKIT=1 docker build --target output -t trimesh/trimesh:latest .
```

There is also a `Makefile` which enables Buildkit, tags the versioned images, and provides access to other targets like `test` and `docs`:
```
# will list the available options
make help

# will build and tag a `trimesh/trimesh:latest` image
# and also tag it with semantic version and git hash
make build

# will build trimesh images and then in a different
# build stage install the testing requirements and
# run all of trimesh's unit tests inside the image
make test

# will build trimesh's docs inside the image and then
# eject the results into the `./html` directory
make docs
```