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

Top comments (0)

Warp.dev image

Warp is the highest-rated coding agent—proven by benchmarks.

Warp outperforms every other coding agent on the market, and gives you full control over which model you use. Get started now for free, or upgrade and unlock 2.5x AI credits on Warp's paid plans.

Download Warp

👋 Kindness is contagious

Discover fresh viewpoints in this insightful post, supported by our vibrant DEV Community. Every developer’s experience matters—add your thoughts and help us grow together.

A simple “thank you” can uplift the author and spark new discussions—leave yours below!

On DEV, knowledge-sharing connects us and drives innovation. Found this useful? A quick note of appreciation makes a real impact.

Okay