awesome-compose/go-mysql-redis
vishal979 207f73ab81 add go mysql redis sample
Signed-off-by: vishal979 <shantapowertech2@gmail.com>
2020-07-04 19:38:53 +05:30
..
vendor add go mysql redis sample 2020-07-04 19:38:53 +05:30
docker-compose.yml add go mysql redis sample 2020-07-04 19:38:53 +05:30
Dockerfile add go mysql redis sample 2020-07-04 19:38:53 +05:30
go.mod add go mysql redis sample 2020-07-04 19:38:53 +05:30
go.sum add go mysql redis sample 2020-07-04 19:38:53 +05:30
main.go add go mysql redis sample 2020-07-04 19:38:53 +05:30
makefile add go mysql redis sample 2020-07-04 19:38:53 +05:30
README.md add go mysql redis sample 2020-07-04 19:38:53 +05:30

Run an application on golang http server, and mysql database and redis datastore(can use as cache).

Project Structure:-

├── Dockerfile
├── go.mod
├── main.go
├── go.sum
├── docker-compose.yml
├── makefile
├── vendor
└── README.md 

docker-compose.yml

The compose file define an application with three services app , mysql and redis. The application is deployed on port 8080 and it maps port 3307 for mysql and 6378 for redis on host, so if you have other instance of mysql or redis running already on port 3306 and port 6379, then also the application will run fine.

makefile

The default goal for make is help, and it looks like this

Usage:
  make [target...]

Useful commands:
  build                          to build the project again after making changes
  compose                        to run the containers
  down                           docker-compose down
  pruneVolume                    remove all dangling volumes
  runLocal                       to run the app locally

To run the containers

make compose

this will remove all the dangling volumes first, then build the project using flag no-cache, and then run the containers.

expected result

docker container ls
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS                    PORTS                               NAMES
fb91b303db93        docker-contribution_app   "./main"                 40 seconds ago      Up 38 seconds             0.0.0.0:8080->8080/tcp              goapp
19a5b083084d        redis:latest              "docker-entrypoint.s…"   40 seconds ago      Up 39 seconds             0.0.0.0:6378->6379/tcp              goapp_redis
3da52c78e384        mysql/mysql-server:5.7    "/entrypoint.sh mysq…"   40 seconds ago      Up 39 seconds (healthy)   33060/tcp, 0.0.0.0:3307->3306/tcp   goapp_mysql

type localhost:8080 in browser if the connection to both the database is successful and ping is possible then you will see

Connection to mysql and redis successful