侧边栏壁纸
  • 累计撰写 38 篇文章
  • 累计创建 81 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

使用Dockerfile文件构建golang运行环境

小李同学
2023-06-29 / 0 评论 / 0 点赞 / 480 阅读 / 403 字 / 正在检测是否收录...

Dockerfile

# Version: 0.0.1
FROM ubuntu:22.04
MAINTAINER Mingze Li "limingze610@163.com"

RUN echo 'deb http://cn.archive.ubuntu.com/ubuntu/ jammy main restricte' \
'deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricte' \
'deb http://cn.archive.ubuntu.com/ubuntu/ jammy univers' \
'deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates univers' \
'deb http://cn.archive.ubuntu.com/ubuntu/ jammy multivers' \
'deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multivers' \
'deb http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multivers' \
'deb http://security.ubuntu.com/ubuntu jammy-security main restricte' \
'deb http://security.ubuntu.com/ubuntu jammy-security univers' \
'deb http://security.ubuntu.com/ubuntu jammy-security multivers' \
> /etc/apt/sources.list

RUN apt update

RUN apt install -y vim
RUN apt install -y sudo
RUN apt install -y wget
RUN apt install -y curl

RUN mkdir -p /home/workspace
WORKDIR /home/workspace

RUN wget -O go.tar.gz https://studygolang.com/dl/golang/go1.19.10.linux-amd64.tar.gz
RUN tar -zxf go.tar.gz -C /usr/local/
RUN ln -sv /usr/local/go/bin/go /bin

ENV TZ Asia/Shanghai
ENV GOPROXY https://goproxy.io,direct
ENV GO111MODULE on
ENV GOROOT /usr/local/go
ENV CGO_ENABLED 1
ENV GOPATH /home/workspace/go

EXPOSE 80
EXPOSE 8080
EXPOSE 8888
EXPOSE 6666

#CMD ["app"]

build

docker build -t="jasonleemz/golang:v0.1"

或者可以关联github,前提是Dockerfile已经存在仓库中
docker build -t="jasonleemz/golang:v0.1" git@github.com:JasonLeemz/golang

将镜像推送到DockerHub

docker push jasonleemz/golang:v0.1

如果提示

denied: requested access to the resource is denied
需要先登录dockerhub,然后再push就可以了

# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: jasonleemz
Password: 
...
Login Succeeded

ERROR: invalid empty ssh agent socket: make sure SSH_AUTH_SOCK is set

eval "$(ssh-agent -s)"
export SSH_AUTH_SOCK="/run/user/1000/ssh-agent.sock"
0

评论区