linux上安装Docker(非常简单的安装方法)
前言
很多同学一看到docker,就说,这个我知道,不就是DOTA 2 游戏吗?这个我天天玩,
大哥,麻烦你看清楚好不好,别宝里宝气的,好不咯,哈哈哈哈
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
提示:以下是本篇文章正文内容,下面案例可供参考
一、虚拟化技术
二.云计算
1.云的分类:
2.IasS和PaaS
三.实验操作:
环境准备: 准备一台全新的centos8的系统 或者Ubuntu 20 server的系统
1.到底使用那个系统?
centos --》有结束日期
centos linux8 --》2021-12-31
centos linux7 --》2024-6-30
centos 是开源的,并且免费
RHEL9 --》red hat enterprice linux 9
red hat 开源,但是收费的 --》商业版本
centos 被red hat收购 ---》centos 成了redhat的试验场
Ubuntu
cali@sanchuang:~/fabric/scripts$ cat /etc/issue
Ubuntu 20.04.2 LTS \n \l
cali@sanchuang:~/fabric/scripts$
debian
centos8.4.2105 -->2c/4G/100G root账号已经比禁用了–》设置密码就启用了
*ubuntu20.04.2 -->2c/4G/100G =====*
2.docker 是什么?
(1)docker --》是一个软件,使用GO语言开发的一个软件, 对容器进行管理容器管理软件
集装箱 装货物 : --》容器 container --》把一个进程装到容器里 --》控制这个进程的资源消耗(cpu,内存)
(2)hypervisor :超级监督者;管理程序
VMware 是美国一个虚拟化厂商 --》VMware(威睿) 是全球桌面到数据中心虚拟化解决方案的领导厂商。
VMware ESXi:专门构建的裸机 Hypervisor
(3)裸机: 没有安装系统的机器 裸机 --》VMware ESXi VMWARE workstation --》 入门级的虚拟化软件 --》低端的
微服务 --》docker
说到底,其实docker的一个容器,背后就是一个进程
(4)Engine 引擎: 核心的部件
**
具体操作:
**
在centos8安装
[root@localhost ~]# hostnamectl set-hostname sc-docker [root@localhost ~]# su - root 上一次登录:二 8月 10 15:27:37 CST 2021从 192.168.0.189pts/0 上 [root@sc-docker ~]#
[root@sc-docker ~]# cat /etc/centos-release CentOS Linux release 8.4.2105 [root@sc-docker ~]#
**## ****
1.卸载旧版本的docker******
\ 续行符号: 继续到下一行
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
#The Docker Engine package is now called docker-ce.
[root@sc-docker ~]# yum install -y yum-utils
2.添加yum仓库文件
添加docker官方的yum仓库文件,一会儿我们需要去docker官方的yum仓库下载软件 [root@sc-docker ~]# yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
添加仓库自:https://download.docker.com/linux/centos/docker-ce.repo [root@sc-docker ~]# 添加阿里云的镜像docker仓库 —》推荐使用 [root@sc-docker ~]# yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
添加仓库自:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo [root@sc-docker ~]# [root@sc-docker yum.repos.d]# cd /etc/yum.repos.d/ 存放所有的yum仓库文件的 [root@sc-docker yum.repos.d]# ls CentOS-Linux-AppStream.repo CentOS-Linux-Devel.repo CentOS-Linux-Media.repo docker-ce.repo CentOS-Linux-BaseOS.repo CentOS-Linux-Extras.repo CentOS-Linux-Plus.repo CentOS-Linux-ContinuousRelease.repo CentOS-Linux-FastTrack.repo CentOS-Linux-PowerTools.repo CentOS-Linux-Debuginfo.repo CentOS-Linux-HighAvailability.repo CentOS-Linux-Sources.repo [root@sc-docker yum.repos.d]# docker-ce.repo 就是我们刚刚下载的
3.安装docker
[root@sc-docker yum.repos.d]# yum install docker-ce docker-ce-cli containerd.io -y
4.启动docker,并且设置docker开机启动
[root@sc-docker yum.repos.d]# systemctl start docker [root@sc-docker yum.repos.d]# systemctl enable docker Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service. [root@sc-docker yum.repos.d]# [root@sc-docker yum.repos.d]# ps aux|grep docker root 16210 0.4 2.0 1368904 79400 ? Ssl 17:29 0:00 /usr/bin/dockerd-H fd:// --containerd=/run/containerd/containerd.sock root 16363 0.0 0.0 12348 1112 pts/0 S+ 17:30 0:00 grep --color=auto docker [root@sc-docker yum.repos.d]#
5.测试运行一个docker容器
[root@sc-docker yum.repos.d]# docker run hello-world Unable to find image ‘hello-world:latest’ locally latest: Pulling from library/hello-world b8dfde127a29: Pull complete Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e 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:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the “hello-world” image from the Docker Hub.
(amd64) - The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading. - 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/
[root@sc-docker yum.repos.d]#
Ubuntu里安装docker
https://docs.docker.com/engine/install/ubuntu/
cali@sanchuang-server:~$ cat /etc/issue Ubuntu 20.04.2 LTS \n \l
cali@sanchuang-server:~$ 卸载旧的docker cali@sanchuang-server:~$ sudo apt-get remove docker docker-engine docker.io containerd runc [sudo] password for cali: Reading package lists… Done Building dependency tree Reading state information… Done E: Unable to locate package docker-engine cali@sanchuang-server:~$
cali@sanchuang-server:~$ sudo apt-get update 更新系统里的所有的能更新的软件
6.安装几个工具软件
cali@sanchuang-server:~$sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
curl 是字符界面的浏览器
gpgkey 是用来验证软件的真伪 --》防伪的 cali@sanchuang-server:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg cali@sanchuang-server:~$
cali@sanchuang-server:~$ echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu
(
l
s
b
r
e
l
e
a
s
e
?
c
s
)
s
t
a
b
l
e
"
∣
s
u
d
o
t
e
e
/
e
t
c
/
a
p
t
/
s
o
u
r
c
e
s
.
l
i
s
t
.
d
/
d
o
c
k
e
r
.
l
i
s
t
>
/
d
e
v
/
n
u
l
l
c
a
l
i
@
s
a
n
c
h
u
a
n
g
?
s
e
r
v
e
r
:
?
(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null cali@sanchuang-server:~
(lsbr?elease?cs)stable"∣sudotee/etc/apt/sources.list.d/docker.list>/dev/nullcali@sanchuang?server:?
cali@sanchuang-server:~$ sudo apt-get update 再次更新系统 Hit:1 http://cn.archive.ubuntu.com/ubuntu focal InRelease Get:2 https://download.docker.com/linux/ubuntu focal InRelease [52.1 kB] Hit:3 http://cn.archive.ubuntu.com/ubuntu focal-updates InRelease Get:4 http://cn.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB] Get:5 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [10.7 kB] Get:6 http://cn.archive.ubuntu.com/ubuntu focal-security InRelease [114 kB] Fetched 277 kB in 3s (95.9 kB/s) Reading package lists… Done
**
7.安装docker-ce软件
** cali@sanchuang-server:~$sudo apt-get install docker-ce docker-ce-cli containerd.io -y
(1)自动启动docker
cali@sanchuang-server:~$ ps aux|grep docker root 3659 0.8 1.9 1309896 78164 ? Ssl 09:39 0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock cali 4816 0.0 0.0 6432 736 pts/0 S+ 09:40 0:00 grep --color=auto docker cali@sanchuang-server:~$
(2)测试 cali@sanchuang-server:~$ sudo docker run hello-world Unable to find image ‘hello-world:latest’ locally latest: Pulling from library/hello-world b8dfde127a29: Pull complete Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e 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:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the “hello-world” image from the Docker Hub.
(amd64) - The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading. - 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/
**cali@sanchuang-server:~$
总结:
1.本篇文章只是简单地介绍了什么是docker,教你如何在Centos安装docker,简单易上手.
2.我个人对于docker的理解就是,它就像一个海量的APP store,只是它不像手机上,我安装了微信就可以马上去视频,docker需要去pull images,是很方便的,像常用的python和MySQL上面都有,只有你想不到的,没有它没有的.
3.最后一句,也是最重要的,一定要动手操作,有任何问题可以评论或者留言哈.
**
如果你看到这里了,麻烦👍 + 关注哈,感谢支持,码字不易,谢谢理解.
**
|