I tried to containerise a GoLang HTTP server



Hi this is Akshay Rao currently working in Annotation.Inc. In this blog I tried to host a simple HTTP server written in GoLang.

Let's Start

  • We will require docker to be installed in PC.
    Go to the project and create a Dockerfile.
    Now we will have to write commands which can will launch the app when the Image is ran.

FROM golang:1.16-alpine - this will pull the official base image of golang
RUN mkdir /app
ADD . /app

      WORKDIR /app
RUN go build project.go or go build project .
CMD [“/app/project”]

    In golang first we compile program and obtain a executable file, then we can run this executable file on any OS.

  • Build the image “docker build -t /name of the image/ .”( docker build -t first-go-project .)
    To check the image has been created or not use “docker image ls”
    Then run docker run -p 8080:8080 -it /docker image/


    Open localhost:8080 u will be able to see the docker image is running.

    if u get stuck the with this error
    Use the command “go env -w GO111MODULE=off”
    Thank you