Docker containers are stateless by default. In order to persist filesystem changes, you must use docker volumes. In this lesson, we will go over how to copy files over to Docker containers, how to create volumes and copy data to them, and also how to mount remote folders for persisting updates.

First start nginx:

docker run -p : --name web --rm nginx

Create a index.html with content just 'foo'

foo

Copy the index.html to nginx default html folder:

docker cp index.html web:/usr/share/nginx/html

Visit the website: localhost:8080, we should be able to see the 'foo'.

Now if we stop the container, and restart it:

docker run -p 8080:80 --name web --rm nginx

We can see the container is statless and we cannot see the word 'foo'.

To persistent the data, we need to add volume:

docker cp index.html web:/usr/share/nginx/html ## copy the index.html

docker run -p : --name web --rm -v web:/usr/share/nginx/html nginx  ## add volume with -v

Now the data is saved and restart the container will still see the data.

最新文章

  1. Css 备忘知识点
  2. java动态绑定的一点注意
  3. 事件异步(EAP)使用事件异步处理一些耗时操作
  4. noi题库(noi.openjudge.cn) 1.8编程基础之多维数组T01——T10
  5. 今天微信群需要人家通过吗?是微信bug吗
  6. ASP.NET 为GridView添加序号列,且支持分页连续累计显示
  7. Python开发专业工具推荐
  8. 【ASP.Net MVC】AspNet Mvc一些总结
  9. Objective-C:自定义Block函数
  10. (转载)MySQL默认INFORMATION_SCHEMA,MySQL,TEST三个数据库用途
  11. eclipse中tomcat内存溢出问题,报PermGen space
  12. UVA12186--树型DP
  13. 编译安装httpd
  14. Java工程师:四个月小白变大咖,你能做到吗?
  15. MYSQL定时任务 触发器
  16. [转]Node.JS使用Sequelize操作MySQL
  17. linux关闭终端响铃
  18. Android-Java-死锁
  19. iOS 应用程序目录结构
  20. 使用Koa2搭建web项目

热门文章

  1. 70.nodejs操作mongodb
  2. AtCoder Grand Contest 018 A - Getting Difference
  3. maven项目引入sqljdbc4 找不到包的完美 解决方案
  4. 从excel 获取内容 模块:xlrd
  5. dp之多重背包(未用二进制优化)
  6. ubuntu-smb共享文件创建
  7. 18/9/16牛客网提高组Day2
  8. Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集
  9. RocketMQ(八):消息发送
  10. 编译安装PHP-7.2.8