How I launch Golang Web App Using Docker

I have recently build and launch one monitoring web app in my current company. which to monitor our internal test and services running on different environment. I have build the app on go(golang) which I have really enjoyed to work. This is the technology stack I used:

  • golang(backend)
  • Gorrila (rest api)
  • javascript
  • chart libraries(d3.js, crossfilter.js and dc.js)

This is my first web app for which I used docker to launch on ECS. it’s running currently on our ECS instance without any issue. I went through some learning process to figure out, how to launch the app on docker. Anyway, I am writing the steps, I followed while launching through docker; May be it will help someone to launch using docker.

  • First Step: Create the Dockerfile

There could be different ways do build the dockerfile, I created following Dockerfile:

Please Note: Just make sure you write this file into your project root directory:

FROM golang:latest

# update debian packages
RUN apt-get update
RUN apt-get -y upgrade
RUN echo yes | apt-get -y install mysql-client
#RUN service mysql start

# Copy the local packages files to the container workspace
RUN mkdir -p /go/src/<project_root_dir>/<project_name>
ENV APP_PATH<project_root_dir>/<project_name>

# copy the local project into the container workspace
ADD . /go/src/$APP_PATH

# Get all dependencies (you can include more)
RUN go get -v \

#Install and create the build
RUN godep go build .
RUN godep go install .

# Run the app command by default when the container starts
ENTRYPOINT <project_name>

# EXPOSE Web FrontEnd

I have used godep as build lib but you can use anything whatever you like or don’t use anything, you can use this step if you don’t use any build lib:
RUN go build . and 
Run go install 

  • Second Step: Build the Docker Image : Simple Command

docker build -t <my-docker-app> Dockerfile

  • Third Step: Run the image:

docker run -p 49160:8080 -i <my-docker-app> 

Now visit to http://localhost:49160 to check your running app 🙂

I would really appreciate any feedback.

3 thoughts on “How I launch Golang Web App Using Docker

Leave a Reply to Sunil Kapil Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s