Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1330493
  • 博文数量: 932
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 10208
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-08 12:28
文章分类

全部博文(932)

文章存档

2021年(1)

2020年(134)

2019年(792)

2018年(5)

我的朋友

分类: 架构设计与优化

2019-05-03 18:11:01

通过这个小例子我们可以进一步加深对Docker volume概念的理解和使用方法。

我们都知道运行基于Docker的Nginx镜像后,访问localhost能看到Nginx默认的首页,这个首页的位置是Nginx镜像内的/usr/share/nginx/html目录下面。

假设我们有个需求,修改Nginx默认的首页成下面的内容:

<html> <head> <title>Custom Website from my containertitle> head> <body> <h1>This is Jerry's custom website.h1> <p>This website is served from my <a href="" target="_blank">SAP Dockera> container.p> body> html> 

下面是详细方法。

命令行-v将主机目录nginx-html挂载到Nginx容器内的/usr/share/nginx/html目录内。

docker run -d -p 1081:80 -v `pwd`/nginx-html:/usr/share/nginx/html --name jerry-custom nginx 

使用vi将主机目录nginx-html下面的index.html修改成自定义内容:


通过交互式的方式进入到docker容器内部:

docker exec -it jerry-custom /bin/sh 

发现Docker容器里的index.html也自动被修改了,内容和主机目录nginx-html下面的一致。


localhost:1081即可看到修改过后的自定义Nginx首页:


要获取更多Jerry的原创文章,请关注公众号"汪子熙":

阅读(484) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~