随笔 - 934, 文章 - 0, 评论 - 249, 阅读 - 345万

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

Mac下使用docker配置Centos7的go开发环境

Posted on   蝈蝈俊  阅读(729)  评论(1编辑  收藏  举报

之前配置Centos6看:https://www.cnblogs.com/ghj1976/p/12344677.html

安装Centos指定版本操作系统

https://hub.docker.com/_/centos?tab=tags 选择你需要安装的centos版本比如我下面选择的是 7.6 版本

% docker pull centos:centos7.6.1810
centos7.6.1810: Pulling from library/centos
ac9208207ada: Pull complete 
Digest: sha256:62d9e1c2daa91166139b51577fe4f4f6b4cc41a3a2c7fc36bd895e2a17a3e4e6
Status: Downloaded newer image for centos:centos7.6.1810
docker.io/library/centos:centos7.6.1810

查看本地镜像

使用以下命令来查看是否已安装了 centos7:

% docker images
REPOSITORY   TAG              IMAGE ID       CREATED         SIZE
centos       latest           f16ccff02e5a   15 hours ago    1.66GB
<none>       <none>           780a1bc94234   28 hours ago    1.62GB
centos       6.9              2199b8eb8390   23 months ago   195MB
centos       centos6.9        2199b8eb8390   23 months ago   195MB
centos       centos7.6.1810   f1cb7c7d58b7   23 months ago   202MB

执行 centos

docker run --privileged=true -it centos:centos7.6.1810 
  • --privileged是以获取系统权限的形式运行,
  • -it是互动模式,跟本地的系统进行交互,调用的本地的终端

保存

在未退出来之前,另开一个窗口,看正在运营的容器ID:

% docker ps    
CONTAINER ID   IMAGE                   COMMAND       CREATED         STATUS         PORTS     NAMES
bf41218a1046   centos:centos7.6.1810   "/bin/bash"   6 minutes ago   Up 6 minutes             infallible_elion

保存这个容器

% docker commit bf41218a1046 centos:myc7go 
sha256:f69db922e983a9cb528760db41015eb87bf38f86fb0022d29e9c6e244ba88d53

docker commit :从容器创建一个新的镜像。
docker commit [选项] <容器ID或容器名> [<仓库名>[:<标签>]]

配置 Centos

# yum install wget
# yum install gcc
# yum install vim

配置golang

在Docker->preference中添加目录共享。

带目录共享重新启动容器

docker run --privileged=true -v /Users/guohongjun/software:/software -it centos:myc7go

-v, --volume=[] 给容器挂载存储卷,挂载到容器的某个目录

参考: Docker run 命令参数及使用

安装go 1.6

删除旧版本go

cd /usr/local/
rm -rf ./go

Download the archive and extract it into /usr/local, creating a Go tree in /usr/local/go

# cd /software/golang
# tar -C /usr/local/ -xzf ./go1.16.linux-amd64.tar.gz 

Add /usr/local/go/bin to the PATH environment variable

增加
export PATH=$PATH:/usr/local/go/bin

确保及时生效
# source /etc/profile

注意,我们在docker中跑centos,默认是不加载 /etc/profile 的,需要在 /root/.bashrc 这个文件增加环境变量。
Docker之/etc/profile不生效得问题

Verify that you've installed Go by opening a command prompt and typing the following command:

# go version
go version go1.16 linux/amd64

配置go编译

docker run --privileged=true -v /Users/guohongjun/Documents/MyCodes/mygocodes:/home/mygocodes -it centos:myc7go 


编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
历史上的今天:
2016-03-01 屏幕分辨率与FPS
2013-03-01 算法导论第三版第二章第一节习题答案
2013-03-01 算法导论第三版第一章习题答案
点击右上角即可分享
微信分享提示