docker 第二天

1、画出docker command的思维导图

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

docker run --name web1 -d -p 8000:80 nginx -v my-volume:/usr/share/nginx/html

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

docker run --name web2 -d -p 8001:80 httpd -v my-volume:/var/www/html

4、进入容器httpd,修改/var/www/html/index.html文件的内容为welcome to httpd

[root@centos7 ~]# 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@contos7 ~]# 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@centos7 ~]# hostname -I #查看宿主机及容器的ip地址
192.168.15.133 172.17.0.1 

[root@centos7 ~]# 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>

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值