DEV Community

Pierangelo
Pierangelo

Posted on

2

Dockerize an existing GOLANG web server

in the golang project folder create a file named Dockerfile and a file named docker-compose.yml

Dockerile

FROM golang:latest
LABEL maintainer "Pierangelo Orizio <pierangelo1982@gmail.com>"
# for install go packages RUN go get /path
RUN go get github.com/go-sql-driver/mysql
# Copy the local package files to the container's workspace.
ADD . /go/src/github.com/pierangelo1982/myproject
# build executable
RUN go install github.com/pierangelo1982/myproject
# execute 
ENTRYPOINT /go/bin/myproject
# Document that the service listens on port 8080.
EXPOSE 8080
Enter fullscreen mode Exit fullscreen mode

N.B: in the paths you can substitute pierangelo1982 with your github username.

For add other GO packages add in dockerfile this command (see line 5 in Dockerfile for see an example):

RUN go get github.com/<nameofthepackages>

docker-compose.yml

version: '2'
services:
  app:
    build: .
    volumes:
      - .:/go/src/github.com/pierangelo1982/myproject
    expose:
      - "8080"
    ports:
      - 8080:8080
Enter fullscreen mode Exit fullscreen mode

From the terminal, from inside the project folder launch this commands:

docker-compose build

and

docker-compose up -d

check with the browser if the app run at the address http://0.0.0.0:8080

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay