air-verse / air

☁️ Live reload for Go apps
GNU General Public License v3.0
17.79k stars 806 forks source link

database local volumes gets deleted when docker-compose down is called #366

Closed jithinlal closed 3 weeks ago

jithinlal commented 1 year ago

air.toml

root="."
tmp_dir="tmp"

[build]
cmd="go build -gcflags=\"all=-N -l\" -o ./bin/main ."
bin="/app/bin"
full_bin="dlv exec --continue --accept-multiclient --listen=:40000 --headless=true --api-version=2 --log /app/bin/main"
log="air_errors.log"
include_ext=["go", "yaml"]
exclude_dir=["tmp"]
delay=1000

[log]
time=true

[misc]
clean_on_exit=true

docker-compose.yml

version: '3'

services:
  db:
    image: postgres
    container_name:db
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: "test"
      POSTGRES_PASSWORD: "test"
      POSTGRES_DB: "test"
      TZ: "UTC"
      PGTZ: "UTC"
    healthcheck:
      test: pg_isready -U postgres
    volumes:
      - ./tmp:/var/lib/postgresql/data

  app:
    container_name:api
    build:
      context: .
      dockerfile: local.Dockerfile
    ports:
      - "9090:9090"
      - "40000:40000"
    security_opt:
      - "seccomp:unconfined"
    cap_add:
      - SYS_PTRACE
    restart: on-failure
    environment:
      PORT: 9090
      DB_CONN: "postgres://test:test@test:5432/chatbot?sslmode=disable"
    volumes:
      - .:/app
    depends_on:
      db:
        condition: service_healthy
    links:
      - db

local.Dockerfile

FROM golang:1.19 as builder

ENV GO111MODULE=on

RUN apt update && apt upgrade -y && \
    apt install -y git \
    make openssh-client

WORKDIR /app

RUN go install github.com/go-delve/delve/cmd/dlv@v1.9.1
RUN go install github.com/cosmtrek/air@v1.40.4

COPY go.mod ./
COPY go.sum ./

RUN go mod download

COPY . .

CMD ["air", "-c", ".air.toml"]

the postgres local tmp folder gets deleted everytime i stop the container, thus losing all the local data

cosmtrek commented 3 weeks ago

@jithinlal change clean_on_exit to false to skip cleanup