2020-11-15 docker容器

作業(yè)1115

1紧索、通過 RPM 安裝 docker 17.03.0 版本并且配置 docker 阿里加速

# rpm...選擇centos7 安裝
#————————————————————————————————————————————————————————————————————————————
# 方法一:
# 添加倉庫:
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安裝:
yum install -y --setopt=obsoletes=0 \
docker-ce-17.03.1.ce-1.el7.centos   docker-ce-selinux-17.03.1.ce-1.el7.centos

systemctl enable --now docker.service
docker version
#----------------------------------------------------------------------------
# 方法二:
# 依賴包 docker-ce-selinux
yum -y install https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm
# 安裝包 docker-ce
yum -y install https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.0.ce-1.el7.centos.x86_64.rpm

'也可以直接一步安裝:
yum -y install https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm   https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.0.ce-1.el7.centos.x86_64.rpm

systemctl enable --now docker.service
docker version

2咖气、通過 docker 安裝一個(gè) LAMP 架構(gòu)

思路:將AMP分別運(yùn)行為3個(gè)容器

1 = ubuntu安裝docker
# step 1: 更新并安裝必要的系統(tǒng)工具
apt update
apt -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安裝GPG證書
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 將阿里源添加至倉庫
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 安裝Docker-CE
apt -y install docker-ce

# Step 5: 檢查
[root@ubuntu1804 ~]#docker version 
Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 17:02:36 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:01:06 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

2 = 運(yùn)行一個(gè)centos容器月而。汗洒。。在此平臺(tái)上安裝AMP

# 啟動(dòng)
'注意:--privileged父款、/usr/sbin/init 實(shí)現(xiàn)命令systemctl的正常使用
[root@ubuntu1804 ~]#docker run -p 80:80 -p 3306:3306 -p 9000:9000 --restart=always --privileged --name=centos -itd centos /usr/sbin/init
d4dc50dc03305884b3868d70006be4ac39b88451d249fca5460a4e66bb080e8f

# 進(jìn)入
[root@ubuntu1804 ~]#docker exec -it centos /bin/bash
[root@d4dc50dc0330 /]#

# 查看發(fā)行版本
[root@214197b4245d /]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core) 

# 換成阿里源
[root@214197b4245d /]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@214197b4245d /]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2595  100  2595    0     0   7654      0 --:--:-- --:--:-- --:--:--  7654

# 緩存
[root@214197b4245d /]#  yum makecache
Failed to set locale, defaulting to C.UTF-8
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
CentOS-8 - AppStream                                                   613 kB/s | 5.8 MB     00:09
CentOS-8 - Base - mirrors.aliyun.com                                   196 kB/s | 2.2 MB     00:11
CentOS-8 - Extras - mirrors.aliyun.com                                 1.6 kB/s | 8.6 kB     00:05
Metadata cache created.

# 相關(guān)包
dnf -y install httpd php php-json php-mysqlnd mariadb-server

# 啟動(dòng)
systemctl enable --now httpd mariadb

# 創(chuàng)建 wordpress庫溢谤、wordpress賬號
mysql -e 'create database wordpress;'
mysql -e 'grant all on wordpress.* to wordpress@"localhost" identified by "centos";'   # 單雙引錯(cuò)開

# 本機(jī)ip
[root@d4dc50dc0330 /]# hostname -I
172.17.0.2 

# 通過scp去宿主機(jī)拉取 wordpress安裝包
# 宿主機(jī)安裝瞻凤。。世杀。
apt -y install lrzsz
# 放入安裝包
[root@ubuntu1804 ~]#ls wordpress-5.4.2-zh_CN.tar.gz 
wordpress-5.4.2-zh_CN.tar.gz

# 容器中安裝相關(guān)工具實(shí)現(xiàn)scp阀参。。瞻坝。
yum -y install openssh-server  ssh
systemctl enable --now sshd

# 拉取安裝包V肟恰!K丁Q眉觥!
'注意:如果從宿主機(jī)推送浮创,容器的root密碼錯(cuò)誤赫模。。蒸矛。
scp 10.0.0.15:/root/wordpress-5.4.2-zh_CN.tar.gz .

# 解壓到 網(wǎng)頁目錄
tar xvf wordpress-5.4.2-zh_CN.tar.gz -C /var/www/html/
# 查看
[root@d4dc50dc0330 /]# ls /var/www/html/
wordpress

# 設(shè)置文件權(quán)限
chown -R apache.apache /var/www/html/

# 測試訪問
http://10.0.0.15/wordpress

瀏覽器訪問:

1605432650600.png

3瀑罗、寫出 docker run 命令的延申指令,如怎么在停止一個(gè) docker 容器的時(shí)候自動(dòng)刪除該容器

# 當(dāng)容器退出時(shí)自動(dòng)移除容器
docker run --rm xxx

'注意: 不能與選項(xiàng) -d 共用

4雏掠、 docker run 命令通過什么參數(shù)能夠?qū)崿F(xiàn)容器隨著 docker 服務(wù)的啟動(dòng)而自動(dòng)啟動(dòng)

docker run --restart=always xxx

# --restart=always:無論容器的退出狀態(tài)如何斩祭,始終重啟容器
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市乡话,隨后出現(xiàn)的幾起案子摧玫,更是在濱河造成了極大的恐慌,老刑警劉巖绑青,帶你破解...
    沈念sama閱讀 212,454評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件诬像,死亡現(xiàn)場離奇詭異,居然都是意外死亡闸婴,警方通過查閱死者的電腦和手機(jī)坏挠,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,553評論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來邪乍,“玉大人降狠,你說我怎么就攤上這事”永悖” “怎么了榜配?”我有些...
    開封第一講書人閱讀 157,921評論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長吕晌。 經(jīng)常有香客問我蛋褥,道長,這世上最難降的妖魔是什么睛驳? 我笑而不...
    開封第一講書人閱讀 56,648評論 1 284
  • 正文 為了忘掉前任烙心,我火速辦了婚禮膜廊,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘弃理。我一直安慰自己,他們只是感情好屎蜓,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,770評論 6 386
  • 文/花漫 我一把揭開白布痘昌。 她就那樣靜靜地躺著,像睡著了一般炬转。 火紅的嫁衣襯著肌膚如雪辆苔。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,950評論 1 291
  • 那天扼劈,我揣著相機(jī)與錄音驻啤,去河邊找鬼。 笑死荐吵,一個(gè)胖子當(dāng)著我的面吹牛骑冗,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播先煎,決...
    沈念sama閱讀 39,090評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼贼涩,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了薯蝎?” 一聲冷哼從身側(cè)響起遥倦,我...
    開封第一講書人閱讀 37,817評論 0 268
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎占锯,沒想到半個(gè)月后袒哥,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,275評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡消略,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,592評論 2 327
  • 正文 我和宋清朗相戀三年堡称,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片艺演。...
    茶點(diǎn)故事閱讀 38,724評論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡粮呢,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出钞艇,到底是詐尸還是另有隱情啄寡,我是刑警寧澤,帶...
    沈念sama閱讀 34,409評論 4 333
  • 正文 年R本政府宣布哩照,位于F島的核電站挺物,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏飘弧。R本人自食惡果不足惜识藤,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,052評論 3 316
  • 文/蒙蒙 一砚著、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧痴昧,春花似錦稽穆、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,815評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至豪娜,卻和暖如春餐胀,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背瘤载。 一陣腳步聲響...
    開封第一講書人閱讀 32,043評論 1 266
  • 我被黑心中介騙來泰國打工否灾, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人鸣奔。 一個(gè)月前我還...
    沈念sama閱讀 46,503評論 2 361
  • 正文 我出身青樓墨技,卻偏偏與公主長得像,于是被迫代替她去往敵國和親挎狸。 傳聞我的和親對象是個(gè)殘疾皇子健提,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,627評論 2 350

推薦閱讀更多精彩內(nèi)容