Compose sample application Go server with an Nginx proxy and a Postgres database

Compose sample application

Go server with an Nginx proxy and a Postgres database

Project structure:

.
├── backend
│   ├── Dockerfile
│   ├── go.mod
│   └── main.go
├── db
│   └── password.txt
├── docker-compose.yaml
├── proxy
│   ├── conf
│   └── Dockerfile
└── README.md

docker-compose.yaml

services:
  backend:
    build: backend
    ...
  db:
    image: postgres
    ...
  proxy:
    build: proxy
    ports:
    - 80:80
    ...

The compose file defines an application with three services proxy, backend and db. When deploying the application, docker-compose maps port 80 of the proxy service container to port 80 of the host as specified in the file. Make sure port 80 on the host is not already being in use.

Deploy with docker-compose

$ docker-compose up -d
Creating network "nginx-golang-postgres_default" with the default driver
Pulling db (postgres:)...
latest: Pulling from library/postgres
...
Successfully built 5f7c899f9b49
Successfully tagged nginx-golang-postgres_proxy:latest
WARNING: Image for service proxy was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating nginx-golang-postgres_db_1 ... done
Creating nginx-golang-postgres_backend_1 ... done
Creating nginx-golang-postgres_proxy_1   ... done

Expected result

Listing containers must show three containers running and the port mapping as below:

80/tcp nginx-golang-postgres_proxy_1 ffa1410b1c8a nginx-golang-postgres_backend "/server" 49 seconds ago Up 48 seconds 8000/tcp nginx-golang-postgres_backend_1 e63be7db7cbc postgres "docker-entrypoint.s…" 49 seconds ago Up 49 seconds 5432/tcp nginx-golang-postgres_db_1 ">
$ docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                NAMES
5e3ecd0289c0        nginx-golang-postgres_proxy     "nginx -g 'daemon of…"   48 seconds ago      Up 48 seconds       0.0.0.0:80->80/tcp   nginx-golang-postgres_proxy_1
ffa1410b1c8a        nginx-golang-postgres_backend   "/server"                49 seconds ago      Up 48 seconds       8000/tcp             nginx-golang-postgres_backend_1
e63be7db7cbc        postgres                        "docker-entrypoint.s…"   49 seconds ago      Up 49 seconds       5432/tcp             nginx-golang-postgres_db_1

After the application starts, navigate to http://localhost:80 in your web browser or run:

$ curl localhost:80
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"]

Stop and remove the containers

$ docker-compose down
Similar Resources

A simple file-based service to stand in for the remote-service proxy on Apigee.

Apigee-Remote-Service-File A simple file-based service to stand in for the remote-service proxy on Apigee. All configuration is done locally in a YAML

Nov 3, 2021

A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a proxy

A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a proxy

Fake-SMS A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a pr

Dec 31, 2022

Handles file uploads & organises files based on your database entities.

Handles file uploads & organises files based on your database entities.

Nov 22, 2022

The source code for workshop Scalable architecture using Redis as backend database using Golang + Redis

The source code for workshop Scalable architecture using Redis as backend database using Golang + Redis

Sep 23, 2022

A restful api's with Gin Framework with a structured project that defaults to PostgreSQL database

A restful api's with Gin Framework with a structured project that defaults to PostgreSQL database

Welcome to Golang Gin boilerplate v2 The fastest way to deploy a restful api's with Gin Framework with a structured project that defaults to PostgreSQ

Oct 15, 2021

Writing an application using Go and PostgreSQL by Henrique Vicente

pgxtutorial This is an accompanying repository of the article Back to basics: Writing an application using Go and PostgreSQL by Henrique Vicente. Feel

Dec 29, 2022

This application is a tool to rapidly create TFS tasks and synchronize them with wiki.

This application is a tool to rapidly create TFS tasks and synchronize them with wiki.

Jan 10, 2022

Go application for rooms booking and reservation

Booking Key functionality Showcase properties Allow for booking room for one or more night Book the Room Notify the guest and the owner Have a Back-en

Dec 28, 2021

A real-time serverless chat application with Go and Vue 3

A real-time serverless chat application with Go and Vue 3

sls-chat-app A real-time serverless chat application with Go and Vue 3. For the

Jul 17, 2022
A simple database application that I was asked to implement as part of a job application process

This is a simple database application that I was asked to implement as part of a job application process. They told me I could choose any languages an

Nov 24, 2021
gin middlewares, just like nginx try-file function

Gin Middleware TryFile This project is to solve the problem that the gin framework processes the dynamic routing file in the front-end compilation fil

Aug 11, 2022
A job queue and scheduler written in Go, backed by Postgres, and available over HTTP
A job queue and scheduler written in Go, backed by Postgres, and available over HTTP

Rickover This holds the code for a scheduler and a job queue written in Go and backed by Postgres. The goals/features of this project are: Visibility

Dec 31, 2022
Simple vanilla Go CRUD application with mongoDB database with its mflix dataset that I use for my thesis about benchmarking REST API and GraphQL.

Go GraphQL Simple vanilla Go CRUD application with mongoDB database with its mflix dataset that I use for my thesis about benchmarking REST API and Gr

Oct 15, 2021
Sample Go REST API implementation with DDD using Clean Architecture.

This layer is a part developed for client-side (mobile, web, etc.) applications to access our domain. It will forward the requests from this layer to the application layer and expose the response it receives from the application layer.

Jan 3, 2023
Go sql layer architecture sample

go-sql-rest-api-template To run the application go run main.go API Design Common HTTP methods GET: retrieve a representation of the resource POST: cre

Jan 15, 2022
A sample url shortener app to test Keploy integration capabilities
A sample url shortener app to test Keploy integration capabilities

Example URL Shortener A sample url shortener app to test Keploy integration capabilities Installation git clone https://github.com/keploy/example-url-

Oct 22, 2022
This application is used as an example HTTP/SQLite application for Litestream tutorials.

This application is used as an example HTTP/SQLite application for Litestream tutorials. It simply maintains a count of HTTP requests and persists it to a SQLite database.

Apr 2, 2022
Oct 1, 2021
A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.
A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

Oct 10, 2021