fix: slim container image... (#6)

* fix: slim container image...

- Add ignore all exept go files in .dockerignore
- Remove unnecessary spaces
* fix: alpine based image, install g++ in build ...
* For trimpath and ldflags s w

* fix: scratch base, static bin, utilize buildkit...

- Use scratch base image
- Use golang buster as build image
- Static bunary
- Utilize buildkit with gomod and build caching

Authored-by: pratikbin <pratikbin+010101@no-reply-github.com>
This commit is contained in:
pratikbin
2022-09-07 12:16:26 +05:30
committed by GitHub
parent 778108e17a
commit 4f8f0cadeb
4 changed files with 28 additions and 23 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
# Ignore everything
*
# But these files...
!**/go.**
!**.go

View File

@@ -1,13 +1,12 @@
FROM golang:alpine3.15
# syntax = docker/dockerfile:latest
FROM golang as build
WORKDIR /app
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod tidy; \
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o lazytainer ./...
WORKDIR /root/
COPY ./go.mod ./go.sum ./
RUN go mod download
COPY ./lazytainer.go .
RUN go build lazytainer.go
FROM alpine:latest
WORKDIR /root/
COPY --from=0 /root/lazytainer ./
CMD ["./lazytainer"]
FROM scratch
COPY --from=build /app/lazytainer /usr/local/bin/lazytainer
ENTRYPOINT ["/usr/local/bin/lazytainer"]

View File

@@ -1,18 +1,18 @@
# Lazytainer - Lazy Load Containers
Putting your containers to sleep
Putting your containers to sleep
[![Docker](https://github.com/vmorganp/Lazytainer/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/vmorganp/Lazytainer/actions/workflows/docker-publish.yml)
---
## How it works
Monitors network traffic for active connections and recieved packets
If traffic looks to be idle, container stops
Monitors network traffic for active connections and recieved packets
If traffic looks to be idle, container stops
If traffic is incoming to stopped container, container starts
## Want to test it?
```
$ git clone https://github.com/vmorganp/Lazytainer
$ cd Lazytainer
$ docker-compose up
$ docker-compose up
```
## Or put in your docker-compose.yaml
@@ -21,10 +21,10 @@ $ docker-compose up
container_name: lazytainer
image: ghcr.io/vmorganp/lazytainer:master
environment:
- PORT=81 # comma separated list of ports...or just the one
- PORT=81 # comma separated list of ports...or just the one
- LABEL=lazytainer # value of lazytainer.marker for other containers that lazytainer checks
# - TIMEOUT=30 # OPTIONAL number of seconds to let container idle
# - MINPACKETTHRESH=10 # OPTIONAL number of packets that must be recieved to keepalive/start container
# - MINPACKETTHRESH=10 # OPTIONAL number of packets that must be recieved to keepalive/start container
# - POLLRATE=1 # OPTIONAL number of seconds to sleep between polls
# - VERBOSE=true # probably set this to false unless you're debugging or doing the initial demo
ports:
@@ -38,7 +38,7 @@ $ docker-compose up
# configuring service ports is container specific. Look up how to do this on your service of choice
command: --port 81 # make this run on the port passed through on lazytainer
network_mode: service:lazytainer
depends_on:
depends_on:
- lazytainer # wait for lazytainer to start before starting
labels:
- "lazytainer.marker=lazytainer" # required label to make it work

View File

@@ -4,10 +4,10 @@ services:
container_name: lazytainer
image: ghcr.io/vmorganp/lazytainer:master
environment:
- PORT=81,82 # comma separated list of ports...or just the one
- PORT=81,82 # comma separated list of ports...or just the one
- LABEL=lazytainer # value of lazytainer.marker for other containers that lazytainer checks
- TIMEOUT=30 # OPTIONAL number of seconds to let container idle
- MINPACKETTHRESH=10 # OPTIONAL number of packets that must be recieved to keepalive/start container
- MINPACKETTHRESH=10 # OPTIONAL number of packets that must be recieved to keepalive/start container
- POLLRATE=1 # OPTIONAL number of seconds to sleep between polls
- VERBOSE=true # probably set this to false unless you're debugging or doing the initial demo
ports:
@@ -21,7 +21,7 @@ services:
image: containous/whoami
command: --port 81
network_mode: service:lazytainer
depends_on:
depends_on:
- lazytainer
labels:
- "lazytainer.marker=lazytainer"
@@ -32,7 +32,7 @@ services:
image: containous/whoami
command: --port 82
network_mode: service:lazytainer
depends_on:
depends_on:
- lazytainer
labels:
- "lazytainer.marker=lazytainer"