以CentOS7爲例,
先安裝docker
再拉取tomcat
然後配置tomcat容器
docker安裝tomcat8並實現目錄映射端口映射
- 卸載舊版本
舊版本的 Docker 稱爲 docker 或者 docker-engine ,使用以下命令卸載舊版本:
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
- 配置yum源
CentOS-Base-Ali.repo
#按照下面的格式來
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
- 然後先清除原來的元數據
yum clean all
- 然後更新yum源緩存
yum makecache fast
- 查看yum倉庫列表
yum repolist
- 安裝依賴包:
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
- 需要container-selinux支持
下載
wget ./ https://mirrors.huaweicloud.com/centos-altarch/7/extras/aarch64/Packages/container-selinux-2.119.1-1.c57a6f9.el7.noarch.rpm
安裝 container-selinux-2.119.1-1.c57a6f9.el7.noarch.rpm
rpm -ivh container-selinux-2.119.1-1.c57a6f9.el7.noarch.rpm
查看container-selinux被安裝情況
rpm -qa | grep container-selinux
下面開始安裝docker-ce
yum -y install docker-ce docker-ce-cli containerd.io
- 查看docker狀態
systemctl status docker
- 啓動docker
systemctl start docker
- 再查看docker狀態
systemctl status docker
- 設置docker開機自啓動
systemctl enable docker
- 查看docker版本
docker -v
配置docker加速器(注意不要出現中文和空格,可以Tab縮進),可以拉取快一些
vim /etc/docker/daemon.json
{
"registry-mirrors":["https://bjtzu1jb.mirror.aliyuncs.com"]
}
cat /etc/docker/daemon.json
- 加載docker配置文件daemon.json
systemctl daemon-reload
- 重啓docker服務
systemctl restart docker
- 查看docker狀態
systemctl status docker
- 拉取tomcat8
docker pull tomcat:8
- 查看鏡像
docker images
創建並啓動tomcat容器
docker run -d --name tomcat8 -p 8081:8080 -v /root/software:/usr/local/tomcat/webapps tomcat:8
-d | 就是在後臺運行容器 |
---|---|
–name | 指定docker名字 |
-p | 指定端口映射,hostport:containerport |
-v | 指定(新建一個)本地目錄映射到容器目錄 |
- 查看運行的docker進程
docker ps -a
- 進入容器
docker exec -it f89 /bin/bash
這個命令是進入已運行的容器。
-i | 以交互模式運行容器,通常與 -t 同時使用; |
---|---|
-t | 爲容器重新分配一個僞輸入終端,通常與 -i 同時使用; |
-d | 後臺運行容器,並返回容器ID; |
進入tomcat容器後
mv webapps.dist/* webapps
rm -rf webapps.dist/
ls -l webapps
linux服務器本地目錄和容器內部聯繫起來
這樣就可以直接在linux服務器本地目錄修改文件了
然後xshell遠程linux服務器,通過xftp可以實現從windows上傳文件
— —
待續……
創作辛苦!
您的每一個點贊就是我努力的前進動力!
更多精彩,請關注本博主!
微信公衆號也已開通,正在更新ing,歡迎關注「碼農coding」!