Skip to content

Commit 6ac068d

Browse files
gloursmilas
andauthored
add configuration to use traefik-golang sample with Docker Dev Environments feature (docker#254)
* add configuration to use traefik-golang sample with Docker Dev Environments feature * use apt-get instead of apt and --no-install-recommends option Co-authored-by: Milas Bowman <milasb@gmail.com> Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
1 parent 70b1d1f commit 6ac068d

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
services:
2+
frontend:
3+
image: traefik:2.6
4+
command: --providers.docker --entrypoints.web.address=:80 --providers.docker.exposedbydefault=false
5+
ports:
6+
# The HTTP port
7+
- "80:80"
8+
volumes:
9+
# So that Traefik can listen to the Docker events
10+
- /var/run/docker.sock:/var/run/docker.sock
11+
depends_on:
12+
- backend
13+
backend:
14+
build:
15+
context: backend
16+
target: dev-envs
17+
volumes:
18+
- /var/run/docker.sock:/var/run/docker.sock
19+
labels:
20+
- "traefik.enable=true"
21+
- "traefik.http.routers.go.rule=Path(`/`)"
22+
- "traefik.http.services.go.loadbalancer.server.port=80"

traefik-golang/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,11 @@ Stop and remove the containers
9292
```
9393
$ docker compose down
9494
```
95+
96+
## Use with Docker Development Environments
97+
98+
You can use this sample with the Dev Environments feature of Docker Desktop.
99+
To develop directly the backend service inside containers, you just need to use the https git url of the sample:
100+
`https://github.com/docker/awesome-compose/tree/master/traefik-golang`
101+
102+
![page](../dev-envs.png)

traefik-golang/backend/Dockerfile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
FROM golang:1.13 AS build
1+
# syntax=docker/dockerfile:1.4
2+
3+
FROM --platform=$BUILDPLATFORM golang:1.18 AS build
24

35
WORKDIR /compose/hello-docker
46
COPY main.go main.go
57
RUN CGO_ENABLED=0 go build -o backend main.go
68

9+
FROM build as dev-envs
10+
11+
RUN <<EOF
12+
apt-get update
13+
apt-get install -y --no-install-recommends git
14+
EOF
15+
16+
RUN <<EOF
17+
useradd -s /bin/bash -m vscode
18+
groupadd docker
19+
usermod -aG docker vscode
20+
EOF
21+
# install Docker tools (cli, buildx, compose)
22+
COPY --from=gloursdocker/docker / /
23+
CMD ["go", "run", "main.go"]
24+
725
FROM scratch
826
COPY --from=build /compose/hello-docker/backend /usr/local/bin/backend
927
CMD ["/usr/local/bin/backend"]

0 commit comments

Comments
 (0)