#安装docker
#!/bin/sh
#关闭SeLinux
sed -i 's/enforcing/disabled/g' /etc/sysconfig/selinux
setenforce 0
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#安装docker
1,curl -fsSL https://get.docker.com/ | sh
2,yum install -y yum-utils
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io
#添加阿里DNS
touch /etc/docker/daemon.json
vi /etc/docker/daemon.json
{
"dns": ["223.5.5.5","223.6.6.6"]
}
#开启docker服务并开启开机自启动
systemctl start docker
systemctl enable docker
centos8 TencentOS
https://blog.csdn.net/qq_31803267/article/details/122960656
#创建名为mynet的网络
docker network create mynet
#安装docker-compose
#(直接下载安装)
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.4.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
#(pip安装)
1、安装python-pip
yum -y inst
直接运行
#设置基础镜像来源
FROM golang:1.17-alpine
#设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
#设置代理
RUN go env -w GOPROXY=https://goproxy.cn,direct
#设置工作目录
WORKDIR /data/
#复制代码
COPY data/. .
#安装环境组件
RUN go mod tidy -compat=1.17
#启动主程序
#RUN go run main.go
#设置端口
EXPOSE 8080
#设置启动命令
CMD ["go","run","main.go"]
构建二进制运行
# 构建成二进制文件
FROM golang:1.17-alpine
# 开启 Go Module
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,direct
WORKDIR /data/
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -o app.api .
# 配置运行环境
FROM alpine:3
# 设置为中国时区
# 设置系统根证书
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add tzdata && \
apk add ca-certificates && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
ENV TZ Asi