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.最后一句,也是最重要的,一定要動手操作,有任何問題可以評論或者留言哈.
**
如果你看到這里了,麻煩👍 + 關注哈,感謝支持,碼字不易,謝謝理解.
**
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/295293.html
標籤:其他
