首页 文章 精选 留言 我的

精选列表

搜索[副语言],共10000篇文章
优秀的个人博客,低调大师

使用 Docker 镜像构建 GO 语言环境

1. 安装 Docker 我当前使用的系统环境是CentOS7,安装Docker使用的命令是yum install docker*。至于其它系统,可以到百度查找其对应的安装方式。 2. 配置 Docker 镜像仓库的地址 目前来说,直接访问 Docker 官网的 DockerHub 会比较慢, 不过幸好现在国内出现了一些 DockerHub 的加速网站。 下面使用 ustc 加速器。 修改文件 /etc/docker/daemon.json,将其内容修改为 1 2 3 { "registry-mirrors" : [ "https://docker.mirrors.ustc.edu.cn" ] } 配置完成后,重启 Docker 服务:systemctl restart docker 这样就可以使用 https://docker.mirrors.ustc.edu.cn 加速器了。 如果 ustc 的加速器速度不够快,还可以尝试一下其它的加速器,具体请参考这里Docker 镜像加速器 3. 下载 golang 的 Docker 镜像 现在就可以下载 golang 的 Docker 镜像了。 在命令行执行命令 docker search golang 就可以查询 golang 镜像的信息了。 1 2 3 4 5 6 $ docker search golang INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io /golang Go (golang) is... 1649 [OK] docker.io docker.io /circleci/golang Go (golang) is... 8 docker.io docker.io /resin/artik710-golang Go (golang) is... 1 docker.io docker.io /resin/artik10-golang Go (golang) is... 0 可以看到,在查询结果中排名第一的,STARS 数量最多, 并且 OFFICIAL 选项下面是 OK ,说明是官方的,所以理论上应该是更可信的。 所以我们就选择使用第一个了。 执行命令 docker pull docker.io/golang 来下载 golang 的官方镜像吧。 $ docker pull docker.io/golang [root@fengbo golang]$ docker pull docker.io/golang Using default tag: latest Trying to pull repository docker.io/library/golang ... latest: Pulling from docker.io/library/golang 723254a2c089: Extracting [===============================> ] 40.83 MB/45.12 MB abe15a44e12f: Download complete 409a28e3cc3d: Download complete 503166935590: Download complete abe52c89597f: Download complete ce145c5cf4da: Downloading [===============> ] 31.36 MB/104.3 MB 96e333289084: Download complete 39cd5f38ffb8: Download complete 39cd5f38ffb8: Pulling fs layer 下载好了之后,查看一下镜像的信息 docker images golang [root@fengbo golang]$ docker images golang REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/golang latest 138bd936fa29 4 weeks ago 733.3 MB 4. 使用 golang 镜像 执行命令docker run -it --rm golang bash,测试一下刚刚下载的 golang 镜像 [root@fengbo golang]$ docker run -it --rm golang bash root@9e46b1255f4b:/go# go version go version go1.9.2 linux/amd64 可以看到,最新的是 1.9.2 版本的。 查看进到容器后的默认目录 root@9e46b1255f4b:/go# pwd /go 看来是在 /go 目录下面。 不过因为我们在创建容器的时候加了 --rm 参数,所以当我们执行 exit 命令退出容器的时候,这个临时容器会被删除。 那我们如何使用这个 golang 的镜像来工作呢? 5. golang 的 Docker 镜像的一种使用方式 首先,如果我们把文件直接写在 Docker 容器里面的话,那么数据是无法持久化的。 即使可以使用 docker cp 命令这样的方式把我们的文件复制到容器内部, 或者把文件从容器中复制出来,但是在操作的时候仍会有很多不方便的地方。 而且,在 golang 的镜像中进行 build 操作的时候,程序依赖的第三方包, 会被下载到容器的 /go 目录下面。如果每次容器都删除, 或者每次创建新的容器的时候,都需要从网络上拉取一次第三方包。 如果网速快的话还好,否则时间浪费的有点儿严重。 所以,我们要把主机的目录映射到容器中,这样就可以把文件进行持久化了。 我们可以使用 docker 命令的 -v 参数,把主机的目录映射到容器中。 不过只使用 -v 参数的话,在容器内部操作目录会有权限限制, 所以还需要增加 --privileged 参数给容器放权。 [root@fengbo golang]$ pwd # 查看当前所在的目录 /root/golang [root@fengbo golang]$ ls -l # 查看当前目录下的子目录和文件等 total 0 drwxrwxrwx. 2 root root 6 Jan 10 01:19 code drwxrwxrwx. 2 root root 6 Jan 10 01:20 go [root@fengbo golang]$ docker run \ # 执行 docker 命令,创建一个新的容器并运行这个容器 > -it \ # 使用交互模式 > --rm \ # 当退出这个容器时,系统自动删除这个容器 > -v /root/golang/go:/go \ # 把主机的目录 '/root/golang/go' 映射为容器内的目录 '/go' > -v /root/golang/code:/code \ # 把主机的目录 '/root/golang/code' 映射为容器内的目录 '/code' > --privileged \ # 给这个容器超级权限,否则无法操作上面映射进去的两个目录 > docker.io/golang \ # 基于镜像 'docker.io/golang' 创建容器 > bash # 在容器内执行命令 'bash' > root@fe6be9f3b22d:/go# # 已经进入容器了 我们可以在容器的目录 /go 和目录 /code 里面创建一些文件, 然后返回主机查看。 root@bb2942f33960:/go# echo "hello" > /go/h.txt # 在容器内,创建文件 '/go/h.txt' 并写入数据 root@bb2942f33960:/go# echo "world" > /code/w.txt # 在容器内,创建文件 '/code/w.txt' 并写入数据 root@bb2942f33960:/go# exit # 退出容器 exit [root@fengbo golang]# find # 已经回到主机了。在主机的 '/root/golang' 目录下查看文件 . ./code ./code/w.txt # 可以看到文件 'w.txt' ./go ./go/h.txt # 以及文件 'h.txt' [root@fengbo golang]# cat go/h.txt hello [root@fengbo golang]# cat code/w.txt world 使用上面的方法,每次创建了容器,都会把主机上指定的目录映射到容器中,修改的数据也会反映到主机上。 6. 方便以后查阅和直接使用,完整命令如下 开启容器 docker run -it --rm -v /root/golang/go:/go -v /root/golang/code:/code --privileged docker.io/golang bash 本文转自郝峰波博客园博客,原文链接:http://www.cnblogs.com/fengbohello/p/8259904.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

各种语言的注释总结--from wiki

Commentscan be classified by: style (inline/block) parse rules (ignored/interpolated/stored in memory) recursivity (nestable/non-nestable) uses (docstrings/throwaway comments/other) Inline comments[edit] Inline comments are generally those that use anewlinecharacter to indicate the end of a comment, and an arbitrarydelimiteror sequence oftokensto indicate the beginning of a comment. Examples: Symbol Languages C Fortran 77and earlier; the 'C' must be in column 1 of a line to indicate a comment. REM,::,: BASIC,COMMAND.COM,cmd.exe, batch files NB. J; from the (historically) common abbreviationNota bene, the Latin for "note well". ⍝ APL; the mnemonic is the glyph (jot overstruck with shoe-down) resembles a desk lamp, and hence "illuminates" the foregoing. # Bourne shelland otherUNIX shells,Cobra,Perl,Python,Ruby,Seed7,Windows PowerShell,PHP,R,Maple % TeX,Prolog,MATLAB,[9]Erlang,S-Lang,Visual Prolog // ActionScript,C (C99),C++,C#,D,Go,Java,JavaScript,Object Pascal(Delphi),Objective-C,PHP,Scala,SASS ' Visual Basic,VBScript,RealBasic ! Fortran, Basic Plus, Inform ; AutoHotkey,AutoIt,Lisp,Common Lisp,Clojure,Rebol,Scheme, many assemblers -- Euphoria,Haskell,SQL,Ada,AppleScript,Eiffel,Lua,VHDL,SGML * COBOL(if fixed-form and * in column 7),PAW, many assemblers, Fortran (if fixed-form and * in column 1) || Curl " Vimscript \ Forth Block comments[edit] Block comments are generally those that use a delimiter to indicate the beginning of a comment, and another delimiter to indicate the end of a comment. In this context,whitespaceandnewlinecharacters are not counted as delimiters. Examples: Symbol Languages ¢~¢,#~#,co~co,comment~comment ALGOL 68 /**/ ActionScript, AutoHotkey, C, C++, C#, D, Go, Java, JavaScript, Objective-C, PHP, PL/I, Scala (can be nested), SASS, SQL,Visual Prolog,CSS #cs#ce AutoIt /++/ D (can be nested) /##/ Cobra(can be nested) <##> Powershell =begin=cut Perl =begin=end Ruby #<tag></code> <code>#</tag> S-Lang {--} Haskell(can be nested) (**) Object Pascal (Delphi), ML, Mathematica,Pascal,Seed7,Applescript,OCaml(can be nested), Standard ML (can be nested), Maple,Newspeak {} Object Pascal (Delphi), Pascal |##| Curl %{%} MATLAB[9](the symbols must be in a separate line) #||# Lisp,Scheme,Racket(can be nested in all three). --[[ ]] Lua "" Smalltalk (comment ...) Clojure 本文转自二郎三郎博客园博客,原文链接:http://www.cnblogs.com/haore147/p/3606079.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册