Category - Docker相关

2024-06-19 16:21:12    59    0    0
  1. #安装docker
  2. #!/bin/sh
  3. #关闭SeLinux
  4. sed -i 's/enforcing/disabled/g' /etc/sysconfig/selinux
  5. setenforce 0
  6. #关闭防火墙
  7. systemctl stop firewalld
  8. systemctl disable firewalld
  9. #安装docker
  10. 1curl -fsSL https://get.docker.com/ | sh
  11. 2yum install -y yum-utils
  12. yum-config-manager \
  13. --add-repo \
  14. https://download.docker.com/linux/centos/docker-ce.repo
  15. yum install docker-ce docker-ce-cli containerd.io
  16. #添加阿里DNS
  17. touch /etc/docker/daemon.json
  18. vi /etc/docker/daemon.json
  19. {
  20. "dns": ["223.5.5.5","223.6.6.6"]
  21. }
  22. #开启docker服务并开启开机自启动
  23. systemctl start docker
  24. systemctl enable docker
  25. centos8 TencentOS
  26. https://blog.csdn.net/qq_31803267/article/details/122960656
  27. #创建名为mynet的网络
  28. docker network create mynet
  29. #安装docker-compose
  30. #(直接下载安装)
  31. curl -L https://get.daocloud.io/docker/compose/releases/download/v2.4.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
  32. chmod +x /usr/local/bin/docker-compose
  33. ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  34. #(pip安装)
  35. 1、安装python-pip
  36. yum -y inst
2024-06-19 15:25:39    52    0    0
  1. golang程序常见docker

直接运行

  1. #设置基础镜像来源
  2. FROM golang:1.17-alpine
  3. #设置时区
  4. ENV TZ=Asia/Shanghai
  5. RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
  6. #设置代理
  7. RUN go env -w GOPROXY=https://goproxy.cn,direct
  8. #设置工作目录
  9. WORKDIR /data/
  10. #复制代码
  11. COPY data/. .
  12. #安装环境组件
  13. RUN go mod tidy -compat=1.17
  14. #启动主程序
  15. #RUN go run main.go
  16. #设置端口
  17. EXPOSE 8080
  18. #设置启动命令
  19. CMD ["go","run","main.go"]

构建二进制运行

  1. # 构建成二进制文件
  2. FROM golang:1.17-alpine
  3. # 开启 Go Module
  4. RUN go env -w GO111MODULE=on
  5. RUN go env -w GOPROXY=https://goproxy.cn,direct
  6. WORKDIR /data/
  7. COPY . .
  8. RUN CGO_ENABLED=0 GOOS=linux go build -a -o app.api .
  9. # 配置运行环境
  10. FROM alpine:3
  11. # 设置为中国时区
  12. # 设置系统根证书
  13. RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
  14. RUN apk --no-cache add tzdata && \
  15. apk add ca-certificates && \
  16. cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
  17. echo "Asia/Shanghai" > /etc/timezone
  18. ENV TZ Asi
Footer