add configuration to use traefik-golang sample with Docker Dev Environments feature (#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>
This commit is contained in:
Guillaume Lours 2022-07-12 12:09:52 +02:00 committed by GitHub
parent 70b1d1f65f
commit 6ac068dfc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,22 @@
services:
frontend:
image: traefik:2.6
command: --providers.docker --entrypoints.web.address=:80 --providers.docker.exposedbydefault=false
ports:
# The HTTP port
- "80:80"
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- backend
backend:
build:
context: backend
target: dev-envs
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
- "traefik.enable=true"
- "traefik.http.routers.go.rule=Path(`/`)"
- "traefik.http.services.go.loadbalancer.server.port=80"

View File

@ -92,3 +92,11 @@ Stop and remove the containers
``` ```
$ docker compose down $ docker compose down
``` ```
## Use with Docker Development Environments
You can use this sample with the Dev Environments feature of Docker Desktop.
To develop directly the backend service inside containers, you just need to use the https git url of the sample:
`https://github.com/docker/awesome-compose/tree/master/traefik-golang`
![page](../dev-envs.png)

View File

@ -1,9 +1,27 @@
FROM golang:1.13 AS build # syntax=docker/dockerfile:1.4
FROM --platform=$BUILDPLATFORM golang:1.18 AS build
WORKDIR /compose/hello-docker WORKDIR /compose/hello-docker
COPY main.go main.go COPY main.go main.go
RUN CGO_ENABLED=0 go build -o backend main.go RUN CGO_ENABLED=0 go build -o backend main.go
FROM build as dev-envs
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends git
EOF
RUN <<EOF
useradd -s /bin/bash -m vscode
groupadd docker
usermod -aG docker vscode
EOF
# install Docker tools (cli, buildx, compose)
COPY --from=gloursdocker/docker / /
CMD ["go", "run", "main.go"]
FROM scratch FROM scratch
COPY --from=build /compose/hello-docker/backend /usr/local/bin/backend COPY --from=build /compose/hello-docker/backend /usr/local/bin/backend
CMD ["/usr/local/bin/backend"] CMD ["/usr/local/bin/backend"]