go kafka docker postgres

// Dockerfile
# ======================
#  GO FIRST STAGE
# ======================

FROM golang:latest as builder
USER ${USER}
WORKDIR /usr/src/app
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
ENV GO111MODULE="on" \
  GOARCH="amd64" \
  GOOS="linux" \
  CGO_ENABLED="0"
RUN apt-get autoclean \
  && apt-get autoremove \
  && apt-get clean \
  && apt-get remove

# ======================
#  GO FINAL STAGE
# ======================

FROM builder
COPY --from=builder /usr/src/app .
RUN apt-get update \
  && apt-get install -y \
  build-essential \
  wget \
  unzip \
  fontconfig \
  locales \
  gconf-service \
  libasound2 \
  libatk1.0-0 \
  libc6 \
  libcairo2 \
  libcups2 \
  libdbus-1-3 \
  libexpat1 \
  libfontconfig1 \
  libgcc1 \
  libgconf-2-4 \
  libgdk-pixbuf2.0-0 \
  libglib2.0-0 \
  libgtk-3-0 \
  libnspr4 \
  libpango-1.0-0 \
  libpangocairo-1.0-0 \
  libstdc++6 \
  libx11-6 \
  libx11-xcb1 \
  libxcb1 \
  libxcomposite1 \
  libxcursor1 \
  libxdamage1 \
  libxext6 \
  libxfixes3 \
  libxi6 \
  libxrandr2 \
  libxrender1 \
  libxss1 \
  libxtst6 \
  ca-certificates \
  fonts-liberation \
  libappindicator1 \
  libnss3 \
  lsb-release \
  xdg-utils \
  python3 \
  g++ \
  make \
  vim \
  git \
  libpq-dev \
  && go build -o main .
EXPOSE 4000
CMD ["./main"]

// docker-compose.yml
version: '3.8'
services:
  ### ===================
  ### APP SERVICE
  ### ===================
  app:
    container_name: app
    restart: always
    build: .
    healthcheck:
      test: echo app is working fine
      timeout: 15s
      interval: 30s
      retries: 3
    env_file:
      - .env
    ports:
      - 4000:4000
    volumes:
      - /usr/src/app
    networks:
      - go_networks
    depends_on:
      - db
      - zookeeper
      - kafka
  ### ===================
  ### DB SERVICE
  ### ===================
  db:
    image: postgres:12-alpine
    restart: always
    healthcheck:
      test: echo db is working fine
      timeout: 15s
      interval: 30s
      retries: 3
    environment:
      POSTGRES_DB: agtran_finance
      POSTGRES_USER: agtran_finance
      POSTGRES_PASSWORD: agtran_finance
    ports:
      - 5432:5432
    volumes:
      - pg-data:/var/lib/postgresql/data
    networks:
      - go_networks
  ### ===================
  ### ZOOKEEPER SERVICE
  ### ===================
  zookeeper:
    image: confluentinc/cp-zookeeper:latest
    restart: always
    healthcheck:
      test: echo zookeeper is working fine
      timeout: 15s
      interval: 30s
      retries: 3
    environment:
      ZOOKEEPER_SERVER_ID: 1
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIMES: 2000
    ports:
      - 2181:2181
    networks:
      - go_networks
  ### ====================
  ### KAFKA SERVICE
  ### ====================
  kafka:
    image: confluentinc/cp-kafka:latest
    restart: always
    healthcheck:
      test: echo kafka is working fine
      timeout: 15s
      interval: 30s
      retries: 3
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE_HOST
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE_HOST:PLAINTEXT,OUTSIDE_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: INSIDE_HOST://kafka:19092,OUTSIDE_HOST://localhost:9092
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    ports:
      - 19092:19092
      - 9092:9092
    networks:
      - restapi_finance_network
    depends_on:
      - go_networks
  ### ====================
  ### ADMINER SERVICE
  ### ====================
  adminer:
    image: adminer
    restart: always
    healthcheck:
      test: echo adminer is working fine
      timeout: 15s
      interval: 30s
      retries: 3
    ports:
      - 8080:8080
    networks:
      - go_networks
  ### ========================
  ### VOLUMES PERSISTENT DATA
  ### ========================
volumes:
  pg-data:
  ### ===================================
  ### NETWORKS GROUP FOR ONE SAME SERVICE
  ### ===================================
networks:
  go_networks:

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source