Error when running docker-compose golang postgres

  docker-compose, dockerfile, goland, postgresql

api.dockerfile

FROM golang:1.13-alpine
ENV GO111MODULE='on'

ARG POSTGRES_DB
ARG POSTGRES_USER
ARG POSTGRES_PASSWORD
ARG POSTGRES_PORT

ENV POSTGRES_DB $POSTGRES_DB
ENV POSTGRES_USER $POSTGRES_USER
ENV POSTGRES_PASSWORD $POSTGRES_PASSWORD
ENV POSTGRES_PORT $POSTGRES_PORT

WORKDIR /go/app

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . /go/app

RUN go build -o ./bin/api .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build

ENTRYPOINT [ "./bin/api" ]

db.dockerfile

FROM postgres:12-alpine
ENV LANG ja_JP.utf8

ARG POSTGRES_DB
ARG POSTGRES_USER
ARG POSTGRES_PASSWORD
ARG POSTGRES_HOST

ENV POSTGRES_DB $POSTGRES_DB
ENV POSTGRES_USER $POSTGRES_USER
ENV POSTGRES_PASSWORD $POSTGRES_PASSWORD
ENV POSTGRES_HOST $POSTGRES_HOST

WORKDIR /docker-entrypoint-initdb.d

COPY ./db .

RUN apk --no-cache update 
    && cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

docker-compose

version: '3'

services:
  api:
    container_name: api
    build:
      context: .
      dockerfile: api.dockerfile
      args:
        - POSTGRES_DB=$POSTGRES_DB
        - POSTGRES_USER=$POSTGRES_USER
        - POSTGRES_PASSWORD=$POSTGRES_PASSWORD
        - POSTGRES_PORT=$POSTGRES_PORT
    depends_on:
      - db
    tty: true
    volumes:
      - ./api:/go/app

  db:
    container_name: db
    build:
      context: .
      dockerfile: db.dockerfile
      args:
        - POSTGRES_DB=$POSTGRES_DB
        - POSTGRES_USER=$POSTGRES_USER
        - POSTGRES_PASSWORD=$POSTGRES_PASSWORD
    volumes:
      - ./db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d

  • when i start docker-compose -d up*

error
ERROR: for api Cannot start service api: OCI runtime create failed: container_linux.go:370: >starting container process caused: exec: "./bin/api": stat ./bin/api: no such file or > directory: unknown
ERROR: Encountered errors while bringing up the project.

Source: Dockerfile Questions

LEAVE A COMMENT