- 一、 安装docker并启动
1、安装需要的包
[root@localhost ~]# yum install -y yum-utils
2、安装阿里云镜像加速:(默认的慢)
[root@localhost ~]# sudo yum-config-manager \
> --add-repo \
> http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3、更新yum
[root@localhost ~]# yum makecache
4、安装docker(ce社区版,ee企业版)
[root@localhost ~]# sudo yum install docker-ce docker-ce-cli containerd.io
5、启动docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.serv
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor p
Active: active (running) since 一 2021-12-27 11:25:44 CST; 18s ago
Docs: https://docs.docker.com
Main PID: 4646 (dockerd)
CGroup: /system.slice/docker.service
└─4646 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/co
6、查看docker版本
[root@localhost ~]# docker version
- 二、下载tomcat,默认下载最新版本
[root@localhost home]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
0e29546d541c: Pull complete
9b829c73b52b: Pull complete
cb5b7ae36172: Pull complete
6494e4811622: Pull complete
668f6fcc5fa5: Pull complete
dc120c3e0290: Pull complete
8f7c0eebb7b1: Pull complete
77b694f83996: Pull complete
0f611256ec3a: Pull complete
4f25def12f23: Pull complete
Digest: sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
- 三、查看所有镜像
[root@localhost home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest fb5657adc892 6 days ago 680MB
nginx latest f6987c8d6ed5 8 days ago 141MB
mysql latest 3218b38490ce 8 days ago 516MB
hello-world latest feb5d9fea6a5 3 months ago 13.3kB
centos latest 5d0da3dc9764 3 months ago 231MB
- 四、启动tomcat容器并进入容器内部
#启动tomcat01,-p参数暴露端口8080
[root@localhost home]# docker run -d -p 8080:8080 --name tomcat01 tomcat
61b5a6f788af52cedfb079f1a85445dc156a129bcc145d65d2f72b948afb8155
#进入tomcat01容器
[root@localhost home]# docker exec -it tomcat01 /bin/bash
root@61b5a6f788af:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp webapps.dist
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps work
#默认最小安装,所以现在还不能放弃tomcat网页,缺少linux命令ll,缺少webapps文件。可通过拷贝webapps.dist文件或改名。就可以访问tomcat了
root@61b5a6f788af:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@61b5a6f788af:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp webapps.dist
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps work
- 五、测试访问