I have created a Dockerfile for a golang back-end app and a docker-compose.yml where I have the the app and Postgres database as services. I can successfully build and run the Dockerfile using docker build -t
command and docker run
command. But when I try to run the docker-compose.yml file using docker-compose up --build
command, it can’t seem to find the executable (.exe) file which should be in the working directory(WORKDIR).
- Dockerfile
FROM golang:1.22-alpine
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
COPY .env .env
RUN go build -o bin ./cmd
EXPOSE 8080
CMD [“/app/bin”]
- docker-compose.yml
version: ‘3.8’
services:
app:
build:.
ports:
– “${PORT}:${PORT}”
depends_on:
– db
environment:
– DSN=postgres://postgres:password@db:5432/tutor-connect
– PORT=${PORT}
volumes:
– .:/app
– /app/vendor
env_file:
– .env
db:
image: postgres:13
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: tutor-connect
ports:
– “5433:5432”
volumes:
– postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
- Error When running docker-compose up build:
tutor-backend-db-1 |
tutor-backend-db-1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
tutor-backend-db-1 |
tutor-backend-db-1 |
tutor-backend-db-1 | 2024-06-10 20:44:35.175 UTC [1] LOG: starting PostgreSQL 13.15 (Debian 13.15-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
tutor-backend-db-1 | 2024-06-10 20:44:35.175 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
tutor-backend-db-1 | 2024-06-10 20:44:35.175 UTC [1] LOG: listening on IPv6 address “::”, port 5432
tutor-backend-db-1 | 2024-06-10 20:44:35.177 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
tutor-backend-db-1 | 2024-06-10 20:44:35.180 UTC [26] LOG: database system was shut down at 2024-06-10 20:42:57 UTC
tutor-backend-db-1 | 2024-06-10 20:44:35.188 UTC [1] LOG: database system is ready to accept connections
tutor-backend-app-1 | exec /app/bin: no such file or directory
tutor-backend-app-1 exited with code 1
I have tried changing the build property of app service in docker-compose.yml file to image and giving it the build image from the Dockerfile but it does not work and the following error persists:
exec /app/bin: no such file or directory
Mahider Tekola is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.