首页  

使用 Dockerfile 构建 gohttphello server 镜像     所属分类 docker 浏览量 597
编译  可执行文件
注意 mac 交叉编译 生成 linux 下的可执行文件
GOOS=linux  go build httphello.go
否则 容器 运行报错
standard_init_linux.go:228: exec user process caused: exec format error

准备镜像制作目录
Dockerfile	
httphello

Dockerfile内容
FROM scratch
ADD httphello /
CMD ["/httphello"]

构建镜像
docker build -t dugang/gohttphello .

运行
docker run -d -p8888:8888  dugang/gohttphello

测试访问
http://127.0.0.1:8888/


# 从零开始创建镜像 不依赖任何base镜像 FROM scratch # 把本地文件添加到 镜像根目录 ADD httphello / // 运行 CMD ["/httphello"]
注意 // http.ListenAndServe("127.0.0.1:8888",nil) http.ListenAndServe("0.0.0.0:8888",nil) 监听地址 一定要写成 0.0.0.0 否则容器外部无法访问
httphello.go package main import "net/http" // 3.处理函数用来接收和输入 func handler(w http.ResponseWriter,r *http.Request) { w.Write([]byte("hello go httpserver")) } func main() { // 1.注册处理函数 http.HandleFunc("/",handler) //2.绑定服务器地址结构 // http.ListenAndServe("127.0.0.1:8888",nil) http.ListenAndServe("0.0.0.0:8888",nil) }
https://gitee.com/dyyx/hellocode/tree/master/web/tech/docker/gohttphello

上一篇     下一篇
分布式任务调度一些技术点

docker 部署 MySQL

temporal部署连接外部的postgres

temporal Java 例子说明

go 包管理工具 go mod

temporal 核心概念