1、升级 系统 yum 最好保持最新状态, sudo yum update
sudo yum update
2、安装 yum-util 其他教程说需要安装,没有亲测不安装会报什么错, sudo yum install -y yum-utils
sudo yum install -y yum-utils
3、配置yum中的docker下载地址,直接yum install docker是不行的,sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
4、查看docker的版本列表,能看到很多版本,yum list docker-ce --showduplicates | sort -r
yum list docker-ce --showduplicates | sort -r
5、安装最新的docker, 执行命令就会自动安装最新的docker版本,sudo yum install docker-ce
sudo yum install docker-ce
6、查看docker安装后的目录,which docker ,默认安装目录为 /usr/bin/docker
7、查看docker的版本,/usr/bin/docker version ,以下为我安装的版本
Client: Docker Engine - Community Version: 19.03.8 API version: 1.40 Go version: go1.12.17 Git commit: afacb8b Built: Wed Mar 11 01:27:04 2020 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.8 API version: 1.40 (minimum version 1.12) Go version: go1.12.17 Git commit: afacb8b Built: Wed Mar 11 01:25:42 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.2.13 GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc: Version: 1.0.0-rc10 GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd docker-init: Version: 0.18.0 GitCommit: fec3683
8、查看docker的CONTAINER ID ,docker ps 命令可以查看,ID 类似于这样 32b37e7b47cd
9、可以先安装个hello-world看看,docker pull hello-world
10、再运行一下安装的 docker , docker run hello-world
[root@localhost uboo]# docker run hello-world 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/
11、我们可以创建一个ubuntu的docker 容器, docker pull ubuntu
12、再进入docker ubuntu 去看看, docker run -ti ubuntu bash
[root@localhost uboo]# docker run -ti ubuntu bash root@f822536177a5:/# ll total 0 drwxr-xr-x. 1 root root 6 May 7 08:57 ./ drwxr-xr-x. 1 root root 6 May 7 08:57 ../ -rwxr-xr-x. 1 root root 0 May 7 08:57 .dockerenv* lrwxrwxrwx. 1 root root 7 Apr 23 11:06 bin -> usr/bin/ drwxr-xr-x. 2 root root 6 Apr 15 11:09 boot/ drwxr-xr-x. 5 root root 360 May 7 08:57 dev/ drwxr-xr-x. 1 root root 66 May 7 08:57 etc/ drwxr-xr-x. 2 root root 6 Apr 15 11:09 home/ lrwxrwxrwx. 1 root root 7 Apr 23 11:06 lib -> usr/lib/ lrwxrwxrwx. 1 root root 9 Apr 23 11:06 lib32 -> usr/lib32/ lrwxrwxrwx. 1 root root 9 Apr 23 11:06 lib64 -> usr/lib64/ lrwxrwxrwx. 1 root root 10 Apr 23 11:06 libx32 -> usr/libx32/ drwxr-xr-x. 2 root root 6 Apr 23 11:06 media/ drwxr-xr-x. 2 root root 6 Apr 23 11:06 mnt/ drwxr-xr-x. 2 root root 6 Apr 23 11:06 opt/ dr-xr-xr-x. 225 root root 0 May 7 08:57 proc/ drwx------. 2 root root 37 Apr 23 11:09 root/ drwxr-xr-x. 1 root root 21 Apr 24 01:07 run/ lrwxrwxrwx. 1 root root 8 Apr 23 11:06 sbin -> usr/sbin/ drwxr-xr-x. 2 root root 6 Apr 23 11:06 srv/ dr-xr-xr-x. 13 root root 0 May 7 07:14 sys/ drwxrwxrwt. 2 root root 6 Apr 23 11:09 tmp/ drwxr-xr-x. 1 root root 18 Apr 23 11:06 usr/ drwxr-xr-x. 1 root root 17 Apr 23 11:09 var/
13、 最基础的ubuntu 系统核心,啥也干不了,先装一些基础的软件才行。apt-get update 升级一下安装命令,时间貌似有点长。
14、再安装一下 wget , apt-get install wget , 让他自己安装吧,好像也挺慢。
15、保持系统运行状态的退出 ,先 ctrl + p ,再 ctrl + q ,就这样退出了,用ps 看一下,系统还是运行的。
[root@localhost uboo]# ps ax | grep docker 3189 ? Ssl 0:03 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock 3854 ? Sl 0:01 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/32b37e7b47cdb86f89915dd78d3d9bfb4b6b18570a19c004f49977f89be670b5 -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-runc 22643 ? Sl 0:00 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/f822536177a50166fa32b0763d1863cefd1cff5c30f38cce25377d786a449a16 -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-runc 22807 pts/0 R+ 0:00 grep --color=auto docker
16、再次想进入Docker 系统的话使用 docker attach CONTAINER ID 就进去了,CONTAINER ID 使用 docker ps 查看。
[root@localhost uboo]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f822536177a5 ubuntu "bash" 6 minutes ago Up 6 minutes trusting_merkle 32b37e7b47cd ubuntu "bash" About an hour ago Up About an hour tender_burnell
[root@localhost uboo]# docker attach 32b37e7b47cd root@32b37e7b47cd:/# ls bin dev home lib32 libx32 mnt proc run srv tmp var boot etc lib lib64 media opt root sbin sys usr
17、查看ubuntu版本 ,cat /etc/issue
root@32b37e7b47cd:/# cat /etc/issue Ubuntu 20.04 LTS \n \l
刚开始学习,就记录到这吧,以后学习多了再更新。
原文:https://www.cnblogs.com/shej123/p/12844215.html