code-server go环境

发布时间 2023-12-14 22:31:49作者: 逢生博客

docker-compose.yml

version: '3'
services:
  code-server:
    build:
      context: ./code-server/
      dockerfile: Dockerfile
    image: code-server:4.19.1
    container_name: code-server
    privileged: true
    # restart: always
    ports:
      - '8080:8080'
    environment:
      TZ: Asia/Shanghai
      # code-server登录密码
      PASSWORD: u12345678
      SUDO_PASSWORD: root12345678
    volumes:
      - /etc/localtime:/etc/localtime
      - /var/run/docker.sock:/var/run/docker.sock
      - ./code-server/local:/home/coder/.local
      - ./code-server/config:/home/coder/.config
      - ./code-server/project:/home/coder/project
    logging:
      driver: "json-file"
      options:
        max-size: "50m"

Dockerfile

FROM codercom/code-server:4.19.1
# apt 国内镜像源
RUN sudo sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN sudo apt-get clean
RUN sudo apt-get update 
RUN sudo apt-get install -y vim 
RUN sudo apt-get install -y curl 
# Go环境依赖
RUN sudo apt-get install -y gcc
RUN sudo apt-get install -y binutils
RUN sudo apt-get install -y bison
RUN sudo apt-get install -y make 
# 安装gvm
RUN curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer | bash -s
RUN /bin/bash -c 'source ~/.gvm/scripts/gvm'
# gvm环境变量
RUN sudo sed -i '$aexport GO111MODULE=on' /etc/profile
RUN sudo sed -i '$aexport GOPROXY=https://goproxy.cn,direct' /etc/profile
RUN sudo sed -i '$aexport G_MIRROR=https://golang.google.cn/dl/' /etc/profile
RUN sudo sed -i '$aexport GO_BINARY_BASE_URL=https://golang.google.cn/dl/' /etc/profile
RUN sudo sed -i '$a[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"' /etc/profile
RUN sudo sed -i '$aexport GOROOT_BOOTSTRAP=$GOROOT' /etc/profile
RUN /bin/bash -c 'source /etc/profile'

RUN sudo sed -i '$aexport GO111MODULE=on' /home/coder/.bashrc
RUN sudo sed -i '$aexport GOPROXY=https://goproxy.cn,direct' /home/coder/.bashrc
RUN sudo sed -i '$aexport G_MIRROR=https://golang.google.cn/dl/' /home/coder/.bashrc
RUN sudo sed -i '$aexport GO_BINARY_BASE_URL=https://golang.google.cn/dl/' /home/coder/.bashrc
RUN sudo sed -i '$a[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"' /home/coder/.bashrc
RUN sudo sed -i '$aexport GOROOT_BOOTSTRAP=$GOROOT' /home/coder/.bashrc
RUN /bin/bash -c 'source /home/coder/.bashrc'

WORKDIR /home/coder/project

gvm管理go版本

# 查看可安装版本
gvm listall
# 查看已安装版本
gvm list
# 安装 Go 版本(1.4>版本,需要加上-B)
gvm install go1.21.5 -B
# 使用指定版本
gvm use go1.21.5
# 设置默认版本
gvm use go1.21.5 --default