Я постоянно получаю ошибку
=> ERROR [8/8] RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . 0.6s
------
> [8/8] RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .:
#16 0.603 no Go files in /app
------
executor failed running [/bin/sh -c CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .]: exit code: 1
Команду RUN я пытался писать по разному, был вариант
RUN go build -o /go-web/cmd/goweb
, но докер продолжает искать go файл в папке /app, что является WORKDIR в докер файле
Мой main файл находится в go-web(корневая папка)/cmd/goweb. Как сделать правильно?
Dockerfile:
# syntax=docker/dockerfile:1
FROM golang:1.17-alpine
# Install git.
RUN apk update && apk add --no-cache git && apk add --no-cach bash && apk add build-base
# Setup folder
WORKDIR /app
# Copy the source from the current directory to the working Directory inside the container
COPY go.mod ./
COPY .env .
RUN go mod download
COPY . .
# Build the Go app
#RUN go build -o /go-web/cmd/goweb
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
# Expose port 8080 to the outside world
EXPOSE 8181
# Run the executable
CMD [ "./main"]
docker-compose:
version: '3.9'
services:
app:
container_name: golang_container
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
- DATABASE_HOST=${DB_HOST}
- DATABASE_PORT=${DB_PORT}
- TEST_POSTGRES_USER=${TEST_DB_USER}
- TEST_POSTGRES_PASSWORD=${TEST_DB_PASSWORD}
- TEST_POSTGRES_DB=${TEST_DB_NAME}
- TEST_DATABASE_HOST=${TEST_DB_HOST}
- TEST_DATABASE_PORT=${TEST_DB_PORT}
tty: true
build:
context: go-web/cmd/goweb
ports:
- 8000:8080
restart: on-failure
volumes:
- .:/app
depends_on:
- postgresdb
networks:
- learning
postgresdb:
image: postgres:latest
container_name: postgres_container
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
- DATABASE_HOST=${DB_HOST}
ports:
- '5432:5432'
volumes:
- ./pg_data:/var/lib/postgresql/data
networks:
- learning
postgresdb_test:
image: postgres:latest
container_name: postgres_test_container
environment:
- POSTGRES_USER=${TEST_DB_USER}
- POSTGRES_PASSWORD=${TEST_DB_PASSWORD}
- POSTGRES_DB=${TEST_DB_NAME}
- DATABASE_HOST=${TEST_DB_HOST}
ports:
- '4568:5432'
volumes:
- ./pg_data_test:/var/lib/postgresql/data
networks:
- learning
volumes:
pg_data:
pg_data_test:
# Networks to be created to facilitate communication between containers
networks:
learning:
driver: bridge