/ examples / chrome / Dockerfile
Dockerfile
 1  # Copyright 2025 Alibaba Group Holding Ltd.
 2  #
 3  # Licensed under the Apache License, Version 2.0 (the "License");
 4  # you may not use this file except in compliance with the License.
 5  # You may obtain a copy of the License at
 6  #
 7  #     http://www.apache.org/licenses/LICENSE-2.0
 8  #
 9  # Unless required by applicable law or agreed to in writing, software
10  # distributed under the License is distributed on an "AS IS" BASIS,
11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  # See the License for the specific language governing permissions and
13  # limitations under the License.
14  
15  FROM golang:1.25.4 AS builder
16  
17  WORKDIR /build
18  
19  COPY go.mod go.sum ./
20  
21  RUN go mod download
22  
23  COPY . .
24  
25  RUN CGO_ENABLED=0 go build -o /build/entrypoint main.go
26  
27  #----------------------
28  # Use a base image with a minimal set of packages.
29  FROM debian:13-slim
30  
31  #----------------------
32  # Install prerequisites, chromium, VNC, and X11 utilities.
33  RUN set -eux; \
34      apt-get update; \
35      apt-get install -y --no-install-recommends \
36        ca-certificates \
37        wget \
38        xdg-utils \
39        chromium \
40        tigervnc-standalone-server \
41        x11-utils; \
42      rm -rf /var/lib/apt/lists/*
43  
44  # Create a non-root user to run Chrome.
45  RUN groupadd -r chrome && useradd -r -g chrome -G audio,video chrome \
46      && mkdir -p /home/chrome/Downloads && chown -R chrome:chrome /home/chrome
47  
48  # Precreate X11 stuff
49  RUN mkdir -p /tmp/.X11-unix
50  RUN chmod 1777 /tmp/.X11-unix
51  
52  COPY --chmod=a+rx chrome.sh /chrome.sh
53  COPY --from=builder --chmod=a+rx /build/entrypoint /entrypoint
54  
55  WORKDIR /home/chrome
56  
57  USER chrome
58  
59  
60  ENTRYPOINT [ "/entrypoint" ]