go 앱을 docker빌드할 때 ENV를 쓰지 않아도 된다!!!




자세한 내용은 이곳을 참조했다.

https://hub.docker.com/_/golang/




Main.go 소스는 다음과 같다.


package main


import (

    "fmt"

)


func main() {

    fmt.Println("Hello World")

}





Dockerfile은 다음과 같다. 


FROM golang:onbuild


RUN mkdir /app

ADD . /app/

WORKDIR /app

RUN go build -o main .

CMD ["/app/main"]



이제 빌드와 실행을 해본다.



$ docker build -t example .

Sending build context to Docker daemon  4.096kB

Step 1/6 : FROM golang:onbuild

# Executing 3 build triggers...

Step 1/1 : COPY . /go/src/app

Step 1/1 : RUN go-wrapper download

 ---> Running in eb597cae57ef

+ exec go get -v -d

Step 1/1 : RUN go-wrapper install

 ---> Running in 3cc20f3cc840

+ exec go install -v

app

 ---> 11d942c55dfb

Removing intermediate container 4eca92f17e78

Removing intermediate container eb597cae57ef

Removing intermediate container 3cc20f3cc840

Step 2/6 : RUN mkdir /app

 ---> Running in 1035dea0ce0d

 ---> 9fbe4249fc32

Removing intermediate container 1035dea0ce0d

Step 3/6 : ADD . /app/

 ---> 8950d77f106e

Removing intermediate container d43b4043d9bf

Step 4/6 : WORKDIR /app

 ---> 465bff3b7275

Removing intermediate container d21a6bdc6c31

Step 5/6 : RUN go build -o main .

 ---> Running in 9e1c1b5a0123

 ---> 9e27407b57d4

Removing intermediate container 9e1c1b5a0123

Step 6/6 : CMD /app/main

 ---> Running in 4dbe90267d84

 ---> a8861bcaebad

Removing intermediate container 4dbe90267d84

Successfully built a8861bcaebad

Successfully tagged example:latest



실행 결과는 다음과 같다.


$ docker run -it --rm --name my-example example

Hello World

'go lang' 카테고리의 다른 글

[golang] imported and not used  (0) 2017.09.05
go 컨퍼런스 자료  (0) 2017.09.01
[golang] if 예제  (0) 2017.08.29
[golang] 반복문 - for / 문 예제  (0) 2017.08.29
[golang] 타입 확인하는 방법 - reflect.TypeOf  (0) 2017.08.29
Posted by '김용환'
,