Docker第二天作业

1、画出docker command的思维导图
请添加图片描述

2、运行一个nginx的容器,要求如下:将容器的80端口映射到宿主机的8000端口,并将数据卷my-volume挂载到/usr/share/nginx/html目录

[root@localhost ~]# docker run --name web -d -p 8000:80 nginx:1.14-alpine
038aedbbe80ae052555ad863cfc2c63dcb4f539b7d75f735f22c5ae2f4df8047
[root@localhost ~]# docker port web			#查询docker端口映射
80/tcp -> 0.0.0.0:8000
80/tcp -> :::8000

[root@localhost ~]# docker volume create my-volume		#创建数据卷
my-volume
[root@localhost ~]# docker volume ls  #查看数据卷
DRIVER    VOLUME NAME
local     my-volume

[root@localhost ~]# docker volume ls  #查看数据卷的信息
DRIVER    VOLUME NAME
local     my-volume
[root@localhost ~]# docker volume inspect my-volume  #查看指定数据卷的详细信息
[
    {
        "CreatedAt": "2022-08-18T15:00:59+08:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/my-volume/_data",
        "Name": "my-volume",
        "Options": {},
        "Scope": "local"
    }
]


[root@localhost ~]# docker run -d -P --name web1 -v my-volume:/usr/share/nginx/html nginx:1.14-alpine	#新建一个名为web1的容器, 并加载一个数据卷到容器的/usr/share/nginx/html/ 目录
404aa47bd62716be0b0486724ea637200903971e1fe3648321712022966029cf
 
[root@localhost ~]# docker inspect web1		#查看该容器的详细信息

3、运行一个httpd的容器,要求如下:将容器的80端口映射到宿主机的8001端口,并将数据库my-volume挂载到/var/www/html

[root@localhost ~]# docker run --name httpd -d -p 8001:80 httpd
3518f9e63170e82dca66cd9442f760ce32390f6370d7bcf8455ad94ce3fd4f8f

[root@localhost ~]# docker run --name httpd1 -d -P -v my-volume:/var/www/html httpd
bdf072f25e2703a11567174863299569cc42867743cc55e27a965e554f0cbcb0

4、进入容器httpd,修改/var/www/html/index.html文件的内容为welcome to httpd
因为httpd容器的index.html文件在/usr/local/apache2/htdocs/路径下,可以进入httpd容器,使用sed命令修改为/var/www/html/index.html并修改其路径权限,由于俺想偷个小懒,就直接使用httpd的原有web页面的文件路径啦。

[root@localhost ~]# docker exec -it httpd /bin/sh
# find / -name index.html	#在httpd容器中找index.html文件并修改其内容
find: '/proc/1/map_files': Operation not permitted
find: '/proc/8/map_files': Operation not permitted
find: '/proc/9/map_files': Operation not permitted
find: '/proc/10/map_files': Operation not permitted
find: '/proc/92/map_files': Operation not permitted
find: '/proc/100/map_files': Operation not permitted
/usr/local/apache2/htdocs/index.html
# echo welcome to httpd > /usr/local/apache2/htdocs/index.html
# cat /usr/local/apache2/htdocs/index.html
welcome to httpd

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS         PORTS                                   NAMES
3518f9e63170   httpd               "httpd-foreground"       17 minutes ago   Up 5 minutes   0.0.0.0:8001->80/tcp, :::8001->80/tcp   httpd
038aedbbe80a   nginx:1.14-alpine   "nginx -g 'daemon of…"   2 hours ago      Up 4 seconds   0.0.0.0:8000->80/tcp, :::8000->80/tcp   web

5、使用curl命令或者浏览器访问nginx容器和httpd容器的web页面

[root@localhost ~]# hostname -I #查看宿主机及容器的ip地址
192.168.15.133 172.17.0.1 

[root@localhost ~]# curl 172.17.0.1:8000 #访问ngnix容器的web页面
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

#访问httpd容器的web页面
[root@localhost ~]# curl 172.17.0.1:8001
welcome to httpd	

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值