Proxy環境でdockerを外に繋ぐ方法(江端個人戦)
助けて頂いた資料:
今、困っていること
Goが動かん。下記(1)~(4)をやっても、
package main
import "fmt"
func main(){
fmt.Printf("Hello world\n")
}
以下のエラーが出てきて取れない。(なんだこれ?)
$ go run hello.go
go: github.com/go-chi/jwtauth@v4.0.2+incompatible: reading github.com/go-chi/jwtauth/go.mod at revision v4.0.2: unknown revision v4.0.2
ubuntu@ip-57:~/codes/hailing_go/docker/app$ go run hello.gogo: github.com/go-chi/jwtauth@v4.0.2+incompatible: reading github.com/go-chi/jwtauth/go.mod at revision v4.0.2: unknown revision v4.0.2
ubuntu@ip-57:~/codes/hailing_go/docker/app$ go mod vendorgo: github.com/go-chi/jwtauth@v4.0.2+incompatible: reading github.com/go-chi/jwtauth/go.mod at revision v4.0.2: unknown revision v4.0.2
ubuntu@ip-57:~/codes/hailing_go/docker/app$ go mod downloadgo: github.com/go-chi/jwtauth@v4.0.2+incompatible: reading github.com/go-chi/jwtauth/go.mod at revision v4.0.2: unknown revision v4.0.2
ubuntu@ip-57:~/codes/hailing_go/docker/app$ go mod initgo: cannot determine module path for source directory /home/ubuntu/codes/hailing_go/docker/app (outside GOPATH, module path must be specified)Example usage:'go mod init example.com/m' to initialize a v0 or v1 module'go mod init example.com/m/v2' to initialize a v2 moduleRun 'go help mod init' for more information.
ubuntu@ip-57:~/codes/hailing_go/docker/app$ go run hello.gogo: github.com/go-chi/jwtauth@v4.0.2+incompatible: reading github.com/go-chi/jwtauth/go.mod at revision v4.0.2: unknown revision v4.0.2
ubuntu@ip-57:~/codes/hailing_go/docker/app$ go mod github.com/go-chi/jwtauth/go.modgo mod github.com/go-chi/jwtauth/go.mod: unknown command
ubuntu@ip-57:~/codes/hailing_go/docker/app$ go mod verifygo: github.com/go-chi/jwtauth@v4.0.2+incompatible: reading github.com/go-chi/jwtauth/go.mod at revision v4.0.2: unknown revision v4.0.2
ubuntu@ip-57:~/codes/hailing_go/docker/app$ go mod whygo: github.com/go-chi/jwtauth@v4.0.2+incompatible: reading github.com/go-chi/jwtauth/go.mod at revision v4.0.2: unknown revision v4.0.2
ubuntu@ip-57:~/codes/hailing_go/docker/app$ go mod init mgo: creating new go.mod: module m
ubuntu@ip-57:~/codes/hailing_go/docker/app$ go run hello.gogo: finding github.com/go-chi/jwtauth v4.0.4+incompatiblego: downloading github.com/go-chi/jwtauth v4.0.4+incompatiblego: extracting github.com/go-chi/jwtauth v4.0.4+incompatiblego: finding github.com/dgrijalva/jwt-go v3.2.0+incompatiblego: downloading github.com/dgrijalva/jwt-go v3.2.0+incompatiblego: extracting github.com/dgrijalva/jwt-go v3.2.0+incompatibleHello world
(とりあえず、ここまで)
試行錯誤で分った事項
(1)/etc/apt/apt.conf を作る
Acquire::http::Proxy "http://12.34.56.789:8080";
Acquire::https::Proxy "http://12.34.56.789:8080"; // (×https://)
Acquire::ftp::Proxy "ftp://12.34.56.789:8080";
(2)/etc/systemd/system/docker.service.d/http-proxy.confを作る
/etc/systemd/system/docker.service.d/http-proxy.conf を力づくで作った(最初はなかった(みたい))。
修正前:
[Service]
Environment="HTTP_PROXY=http://12.34.56.789:8080/" "HTTPS_PROXY=https://12.34.56.789:8080" "NO_PROXY=localhost,127.0.0.1,.12.34.56.789"
修正後:
[Service]
Environment="HTTP_PROXY=http://12.34.56.789:8080/" "HTTPS_PROXY=http://12.34.56.789:8080" "NO_PROXY=localhost,127.0.0.1,.12.34.56.789"(なんのことはない、HTTPS_PROXY の "https:"→"http:" としただけ。ただし、これは、個々の環境に依存する問題だと思う)
(3)関係のありそうな"Dockerfile"に片っ端から、以下を書き込む(関係ありそうなファイルは2つ。hitachi_ride_hailing_go/docker/postgis-pgrouting/Dockerfile
hitachi_ride_hailing_go/docker/app/Dockerfile)
ENV http_proxy http://12.34.56.789:8080
ENV https_proxy http://12.34.56.789:8080(一番最初の”RUN”の前に書き込んでおくとよい)
(4)シェルに以下を書き込んでおく(設定方法は後で調べる)
export http="http://12.34.56.789:8080"
export https="http://12.34.56.789:8080"