docker练习

一、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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值