一、Docker安装Nginx
1.搜索镜像
docker search nginx
2.下载镜像
docker pull nginx
3.查看镜像
[root@bogon /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 7 months ago 141MB
4.以后台方式进入容器,并给容器命名为nginx01,同时设置它的端口
-d 后台运行
-name 给容器命名
-p 宿主机端口:容器内部端口
[root@bogon /]# docker run -d --name nginx01 -p 1100:80 nginx
ef7c96a0a84a8f0570349e77349af06e6355798e0fa77d9f228ce5658db6da7a
5.测试
[root@bogon /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ef7c96a0a84a nginx "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:1100->80/tcp, :::1100->80/tcp nginx01
134d2c961572 centos "/bin/bash" 5 hours ago Up 5 hours focused_buck
[root@bogon /]# curl localhost:1100
进入容器
[root@bogon /]# docker exec -it nginx01 /bin/bash
root@ef7c96a0a84a:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
二、Docker安装tomcat
tomcat官方文档
官方下载方式:
rm表示用完即删
[root@bogon yang]# docker run -it --rm tomcat:9.0
所以我们还用老方式,首先下载tomcat
[root@bogon yang]# docker pull tomcat
启动运行
[root@bogon yang]# docker run -d -p 1122:8080 --name tomcat01 tomcat
测试访问没有问题
进入容器
[root@bogon yang]# docker exec -it tomcat01 /bin/bash
root@d0ab3917e369:/usr/local/tomcat# ll
bash: ll: command not found
root@d0ab3917e369:/usr/local/tomcat# ls -al
total 132
drwxr-xr-x 1 root root 30 Dec 22 2021 .
drwxr-xr-x 1 root root 20 Dec 22 2021 ..
-rw-r--r-- 1 root root 18994 Dec 2 2021 BUILDING.txt
-rw-r--r-- 1 root root 6210 Dec 2 2021 CONTRIBUTING.md
-rw-r--r-- 1 root root 60269 Dec 2 2021 LICENSE
-rw-r--r-- 1 root root 2333 Dec 2 2021 NOTICE
-rw-r--r-- 1 root root 3378 Dec 2 2021 README.md
-rw-r--r-- 1 root root 6905 Dec 2 2021 RELEASE-NOTES
-rw-r--r-- 1 root root 16517 Dec 2 2021 RUNNING.txt
drwxr-xr-x 2 root root 4096 Dec 22 2021 bin
drwxr-xr-x 1 root root 22 Aug 5 08:19 conf
drwxr-xr-x 2 root root 4096 Dec 22 2021 lib
drwxrwxrwx 1 root root 80 Aug 5 08:19 logs
drwxr-xr-x 2 root root 159 Dec 22 2021 native-jni-lib
drwxrwxrwx 2 root root 30 Dec 22 2021 temp
drwxr-xr-x 2 root root 6 Dec 22 2021 webapps
drwxr-xr-x 7 root root 81 Dec 2 2021 webapps.dist
drwxrwxrwx 2 root root 6 Dec 2 2021 work
root@d0ab3917e369:/usr/local/tomcat# cd webapps
root@d0ab3917e369:/usr/local/tomcat/webapps# ls
发现问题:1、1inux命令少了,2。没有webapps。阿里云镜像的原因。默认是最小的镜像,所有不必要的都剔除掉,保证最小可运行的环境。
所以接下来这样做
root@d0ab3917e369:/usr/local/tomcat/webapps# ls
root@d0ab3917e369:/usr/local/tomcat/webapps# cd ..
root@d0ab3917e369:/usr/local/tomcat# ls
BUILDING.txt NOTICE RUNNING.txt lib temp work
CONTRIBUTING.md README.md bin logs webapps
LICENSE RELEASE-NOTES conf native-jni-lib webapps.dist
root@d0ab3917e369:/usr/local/tomcat# cd webapps.dist
root@d0ab3917e369:/usr/local/tomcat/webapps.dist# ls
ROOT docs examples host-manager manager
root@d0ab3917e369:/usr/local/tomcat/webapps.dist# cd ..
root@d0ab3917e369:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@d0ab3917e369:/usr/local/tomcat# cd webapps
root@d0ab3917e369:/usr/local/tomcat/webapps# ls
ROOT docs examples host-manager manager