2
1

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.

ginをdockerで動かす 〜Go Modules管理版〜

Posted at

以前、ginの依存関係をdepで管理していたが、GoModulesでの管理もやってみる
main.go の内容や操作などは以前の記事を参考にしてください

docker-compose.yml

docker-compose.yml
services:
  app:
    container_name: gin_app
    image: golang:1.12.0-alpine
    volumes:
      - .:/go/src/app
    command: >
      sh -c "cd /go/src/app &&
      apk update &&
      apk add --no-cache git &&
      GO111MODULE=off go get -u github.com/codegangsta/gin &&
      go mod init || : &&
      gin -i run"
    ports:
      - 3001:3001
    environment:
      GO111MODULE: "on"

変更点

  • container_nameの変更(これは特に意味はない)
  • environmentに GO111MODULE: "on" を追加
  • commandを修正
    • depのインストールやinitを削除
    • ライブリロード用のginはGoModulesに対応していないため暫定でoffにしてget
    • 初期化処理を追加 go mod init

起動

$ docker-compose up

初回起動時は

  • go.mod
  • so.sum
  • gin-bin

が作成される

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?