官术网_书友最值得收藏!

main.go

Let's create a bare minimum Go program so that we can use it in the Docker image. It will take the NAME environmental variable and print <NAME> is your uncle. and then quit:

package main 
 
import ( 
    "fmt" 
    "os" 
) 
 
func main() { 
    fmt.Println(os.Getenv("NAME") + " is your uncle.") 
} 

Now that we have all the code in place, let's build the Docker image using the Dockerfile file:

$ cd docker
$ tree
.
├── Dockerfile
└── main.go"
0 directories, 2 files $ # -t tag lets us name our docker images so that we can easily refer to them $ docker build . -t hello-uncle Sending build context to Docker daemon 3.072 kB Step 1/5 : FROM golang:1.9.1 ---> 99e596fc807e Step 2/5 : ADD . /go/src/hello ---> Using cache ---> 64d080d7eb39 Step 3/5 : RUN go install hello ---> Using cache ---> 13bd4a1f2a60 Step 4/5 : ENV NAME Bob ---> Using cache ---> cc432fe8ffb4 Step 5/5 : ENTRYPOINT /go/bin/hello ---> Using cache ---> e0bbfb1fe52b Successfully built e0bbfb1fe52b $ # Let's now try to run the docker image. $ docker run hello-uncle Bob is your uncle. $ # We can also change the environment variables on the fly. $ docker run -e NAME=Sam hello-uncle Sam is your uncle.
主站蜘蛛池模板: 古丈县| 栾川县| 溆浦县| 元谋县| 新乡县| 绥棱县| 浪卡子县| 钟祥市| 榕江县| 沙湾县| 五寨县| 汽车| 错那县| 澄迈县| 离岛区| 扎鲁特旗| 泽库县| 运城市| 新民市| 信阳市| 墨玉县| 镇沅| 九龙城区| 浪卡子县| 阳江市| 绥滨县| 辉南县| 吕梁市| 巴楚县| 简阳市| 肥东县| 甘德县| 郁南县| 威海市| 瑞金市| 深水埗区| 中江县| 南靖县| 包头市| 合山市| 得荣县|