Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to run golang using docker?

I’m trying to use docker with go lang & PostgreSQL

I have this structure for the project:

-project_name
   - src
     - app
     - config
     - main.go
     - .env
     - docker-compose.yml 
     - Dockerfile

the docker-compose.yml file contains ( I need GO server & PostgreSQL)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

version: '3.9'
services:
  app:
    container_name: logger_app
    build: ..
    ports:
      - "12000:12000"
    restart: on-failure
    volumes:
      - .:/app
    depends_on:
      - postgres
    networks:
      - MYAPP

  postgres:
    image: postgres:latest
    container_name: postgres_db
    environment:
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_NAME}
      - DATABASE_HOST=${DB_HOST}
    ports:
      - '5432:5432'
    networks:
      - MYAPP

networks:
  MYAPP:
    driver: bridge

The Dockerfile contains:

FROM golang:1.18 as builder

RUN mkdir /app
WORKDIR /app

COPY . .

RUN go get -d -v ./...

RUN go install -v ./...


RUN go build -o /build

EXPOSE 12000

CMD [ "/build" ]

when I run docker-compose up –build I got this error:

failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount868285600/Dockerfile: no such file or directory
ERROR: Service 'app' failed to build : Build failed

>Solution :

Change the build line to build: . line. The compose file and Dockerfile are in the same directory.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading