centos7.6 64bit安装docker,下载32位的ubuntu镜像,并运行此镜像,且在容器中装上golang的开发环境

centos版本:

[root@localhost data]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@localhost data]# 

centos是64位的:

[root@localhost docker]# getconf LONG_BIT
64

添加软件源信息:

[root@localhost data]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

安装docker-ce:

[root@localhost data]# yum install docker-ce
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.njupt.edu.cn
 * epel: mirrors.njupt.edu.cn
 * extras: mirrors.njupt.edu.cn
 * updates: mirrors.njupt.edu.cn
docker-ce-stable                                                                                                                                                      | 3.5 kB  00:00:00     
(1/2): docker-ce-stable/x86_64/primary_db                                                                                                                             |  32 kB  00:00:00     
(2/2): docker-ce-stable/x86_64/updateinfo                                                                                                                             |   55 B  00:00:00     
Resolving Dependencies
--> Running transaction check

查看docker版本:

[root@localhost data]# docker -v
Docker version 19.03.1, build 74b1e89

启动docker服务:

[root@localhost data]# systemctl start docker

允许开机启动docker:

[root@localhost data]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

测试hello-world:

[root@localhost data]# docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
[root@localhost data]# systemctl start docker.s
docker.service  docker.socket   
[root@localhost data]# systemctl start docker
[root@localhost data]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:451ce787d12369c5df2a32c85e5a03d52cbcef6eb3586dd03075f3034f10adcd
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

发现下个hello-world速度有点慢,更新镜像源,在/etc/docker下面修改daemon.json文件如以下,
如果没有此文件,直接创建即可(我是直接创建的):

[root@localhost data]# cd /etc/docker/
[root@localhost docker]# ll
total 4
-rw-------. 1 root root 244 Aug 29 21:45 key.json
[root@localhost docker]# vim daemon.json
{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}

记着,更新源之后,要重启docker:

[root@localhost docker]# systemctl restart docker

以上,在centos上安装docker已完成。





由于业务需要,我得下个i386/ubuntu:

[root@localhost docker]# docker pull i386/ubuntu
Using default tag: latest
latest: Pulling from i386/ubuntu
e777d477ce90: Pull complete 
e0aa7d8210ab: Pull complete 
05340dfc06a9: Pull complete 
f2f193f23089: Pull complete 
Digest: sha256:8fc36de4b957529f5a274da741739aa47b899368318c88bb6bebf9d9e6b0ccd0
Status: Downloaded newer image for i386/ubuntu:latest
docker.io/i386/ubuntu:latest

pull的速度巨快。

运行此ubuntu:

[root@localhost nb]# docker run -it --name ubuntu386 i386/ubuntu /bin/bash
root@099ac84db527:/# 
root@099ac84db527:/# getconf LONG_BIT
32

开始搞golang了:

root@099ac84db527:/# apt update
Get:1 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]           
Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://security.ubuntu.com/ubuntu bionic-security/main i386 Packages [463 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]      
Get:6 http://archive.ubuntu.com/ubuntu bionic/universe i386 Packages [11.3 MB]
Get:7 http://security.ubuntu.com/ubuntu bionic-security/universe i386 Packages [746 kB]
Get:8 http://security.ubuntu.com/ubuntu bionic-security/restricted i386 Packages [5385 B]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/multiverse i386 Packages [4348 B]
Get:10 http://archive.ubuntu.com/ubuntu bionic/main i386 Packages [1328 kB]
Get:11 http://archive.ubuntu.com/ubuntu bionic/restricted i386 Packages [13.5 kB]
Get:12 http://archive.ubuntu.com/ubuntu bionic/multiverse i386 Packages [177 kB]
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [745 kB]
Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse i386 Packages [7418 B]
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/restricted i386 Packages [12.7 kB]
Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1250 kB]
Get:17 http://archive.ubuntu.com/ubuntu bionic-backports/universe i386 Packages [4219 B]
Get:18 http://archive.ubuntu.com/ubuntu bionic-backports/main i386 Packages [2493 B]
Fetched 16.5 MB in 7s (2425 kB/s)                                                                                                                                                           
Reading package lists... Done
Building dependency tree       
Reading state information... Done
4 packages can be upgraded. Run 'apt list --upgradable' to see them.

root@099ac84db527:/# apt install golang
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
.
.
.

golang版本:

root@099ac84db527:/# go version
go version go1.10.4 linux/386

看golang的环境变量:
注意 GOPATH是自动生成的,指向当前用户目录下的go目录,这样方便服务器上的多人开发

root@099ac84db527:~/go/src# go env
GOARCH="386"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_386"
GCCGO="gccgo"
GO386="387"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build865623819=/tmp/go-build -gno-record-gcc-switches"

写一个标准程序:

root@099ac84db527:~/go/src/helloworld# cat helloworld.go 
package main

import "fmt"

func main() {

        fmt.Printf("Hello nb, %s!\n", "chenjuan")

}
root@099ac84db527:~/go/src/helloworld# go run helloworld.go 
Hello nb, chenjuan!





至此,在centos特定64bit版本上安装docker,并下载32位的ubuntu镜像,并运行此镜像,且在容器中装上golang的开发环境,搞定,收工。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值