go docker application deployment (a)

go docker application deployment

1. Create hello.go

//hello.go
package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello, World!")
}

2. Set go compilation environment

GOOS=linux   //编译到linux
GOARCH=amd64  //64位,如果镜像系统是32位,则GOARCH=386
go build

3. Write Dockerfile
one: so out of large image files.

FROM golang

COPY ./hello /tmp/hello

WORKDIR /tmp/

RUN chmod +x hello

Method two: Construction minimized (recommended)

FROM alpine

COPY ./hello /tmp/hello

WORKDIR /tmp/hello

RUN chmod +x hello

ENTRYPOINT ["./hello"]

4. Construction of the mirror

docker build -t hello-image .
docker images //查看镜像

5. Run the container

docker run hello-image ./hello

6.Q: we need to Golang container and container Mysql associate, then we need to how to do it?

A: increase command --link mysql: mysql Mysql let Golang container and container interconnected; by --link, you can use the alias of its associated container access directly in the container, rather than by IP, but can only solve the stand-alone --link correlation between the containers, in the case of multi-machine distributed, otherwise need to be connected by

Guess you like

Origin www.cnblogs.com/tomtellyou/p/12625539.html