Skip to main content

Docker

And, again :) this short note is only about my needs, to keep the command and templates that I used in my investigations.

Shell commands

Command to login to docker registry:

docker login localhost:8080

# $HOME/.docker/config.json

Push image to remote registry:

# docker image tag myimage registry-host:5000/myname/myimage:v1
docker image tag test-app-ui:v1 aganyushkin/test-app-ui:v1
docker push aganyushkin/test-app-ui:v1

https://docs.docker.com/language/golang/build-images/

Images

Angular

Yes, so simple, but it is a quick solution for testing and investigations:

Dockerfile
# Stage 1
FROM node:18-alpine as build-step
RUN mkdir -p /app
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
RUN npm run build --prod

# Stage 2
FROM nginx:1.17.1-alpine
COPY --from=build-step /app/dist/test-app-ui/browser /usr/share/nginx/html

Can check and use image with following commands.

shell
# docker build -t test-app-ui:v1 .
# docker run -it -p 8080:80/tcp --rm --name test-app-ui test-app-ui:v1
# docker image tag test-app-ui:v1 aganyushkin/test-app-ui:v1
# docker push aganyushkin/test-app-ui:v1

GO

Dockerfile
# syntax=docker/dockerfile:1

FROM golang:alpine AS builder

LABEL stage=gobuilder
ENV CGO_ENABLED 0
ENV GOOS linux

RUN apk update --no-cache && apk add --no-cache tzdata
WORKDIR /build
ADD go.mod .
ADD go.sum .
RUN go mod download
COPY . .
# RUN go build -ldflags="-s -w" -o /app/hello . /hello.go
RUN go build -ldflags="-s -w" -o /build/application ./cmd/main.go

FROM alpine

ENV TEST_APP_BFF_PORT 7777
ENV MINUS_SRC_HOST_PORT 'host:7777'
ENV MUL_SRC_HOST_PORT 'host:7777'
ENV PLUS_SRC_HOST_PORT 'host:7777'

RUN apk update --no-cache && apk add --no-cache ca-certificates
COPY --from=builder /usr/share/zoneinfo/America/New_York /usr/share/zoneinfo/America/New_York
ENV TZ America/New_York
WORKDIR /app
COPY --from=builder /build/application /app/application
CMD ["/app/application"]

Command to use that image.

shell
# docker build -t test-app-bff:v1 .
# docker run -it -p 8081:7777/tcp --rm --name test-app-bff test-app-bff:v1
## docker run -it --rm --name test-app-bff test-app-bff:v1 ls -l /app
# docker image tag test-app-bff:v1 aganyushkin/test-app-bff:v1
# docker push aganyushkin/test-app-bff:v1