作業(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)如何斩祭,始終重啟容器