5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

dockerでginを取り敢えず動かしたい

Posted at

そんな人向け
ライブリロード対応だよ:relaxed:

準備

1.docker-compose.yml

docker-compose.yml
version: '3'

services:
  app:
    container_name: gin
    image: golang:1.12.0-alpine
    volumes:
      - .:/go/src/app
    command: >
      sh -c "cd /go/src/app &&
      apk update &&
      apk add --no-cache git &&
      go get -u github.com/codegangsta/gin &&
      go get -u github.com/golang/dep/cmd/dep &&
      dep init ||
      dep ensure &&
      gin -i run"
    ports:
      - 3001:3001

2.main.go

main.go
package main

import "github.com/gin-gonic/gin"

func main() {
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	r.Run()
}

起動

$ docker-compose up

確認

$ curl http://localhost:3001/ping
{"message":"pong"}

停止

$ docker-compose down
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?