更新系统
root@cchen:~# sudo apt-get update
Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal InRelease
Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates InRelease
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports InRelease [108 kB]
Hit:4 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security InRelease
Hit:5 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease
Fetched 108 kB in 1s (212 kB/s)
Reading package lists... Done
root@cchen:~#
安装docker-ce
因为我已经装了
所以没有安装的状态条
root@cchen:~# sudo apt-get install docker-ce
Reading package lists... Done
Building dependency tree
Reading state information... Done
docker-ce is already the newest version (5:20.10.14~3-0~ubuntu-focal).
0 upgraded, 0 newly installed, 0 to remove and 64 not upgraded.
root@cchen:~#
查看版本号
root@cchen:~# docker -v
Docker version 20.10.14, build a224086
拉取最新tomcat镜像
root@cchen:~# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
dbba69284b27: Pull complete
9baf437a1bad: Pull complete
6ade5c59e324: Pull complete
b19a994f6d4c: Pull complete
43c0aceedb57: Pull complete
24e7c71ec633: Pull complete
612cf131e488: Pull complete
dc655e69dd90: Pull complete
efe57b7441f6: Pull complete
8db51a0119f4: Pull complete
Digest: sha256:263f93ac29cb2dbba4275a4e647b448cb39a66334a6340b94da8bf13bde770aa
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
查看镜像是否拉取成功
root@cchen:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress latest 744143078625 6 days ago 605MB
tomcat latest b00440a36b99 12 days ago 680MB
mysql 5.6 dd3b2a5dcb48 3 months ago 303MB
hello-world latest feb5d9fea6a5 6 months ago 13.3kB
运行tomcat
root@cchen:~# docker run -p 8080:8080 -d tomcat
fcfa0e852147040c05c7822e4de4fdcdf0fc427f950de29501c44c765a73d887
记得开放8080端口
直接访问ip:8080 发现错误404
root@cchen:~# docker exec -it fcfa0e852147 /bin/bash
root@fcfa0e852147:/usr/local/tomcat#
root@fcfa0e852147:/usr/local/tomcat# cd ./webapps
root@fcfa0e852147:/usr/local/tomcat/webapps# ls -l
total 0
root@fcfa0e852147:/usr/local/tomcat/webapps#
root@fcfa0e852147:/usr/local/tomcat#
root@fcfa0e852147:/usr/local/tomcat# rm -rf webapps
root@fcfa0e852147:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp work
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps.dist
root@fcfa0e852147:/usr/local/tomcat# mv webapps.dist webapps
root@fcfa0e852147:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp work
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps
root@fcfa0e852147:/usr/local/tomcat#