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.

[Docker] Create Docker Volumes for Persistent Storage的更多相关文章

  1. Docker(10)- docker create 命令详解

    如果你还想从头学起 Docker,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1870863.html 作用 创建一个新的容器但不启动它 ...

  2. Docker学习--->>Docker的认识,安装,及常用命令熟悉

    Docker是什么? 在平常的软件开发中,会面临着开发不同的程序或服务需要不同的环境.而在该环境上开发完成后,想要在其他的环境上部署,则需要自己去重新部署,而Docker的出现使得这样的迁移变得容易. ...

  3. Centos + docker,Ubuntu + docker介绍安装及详细使用

    docker笔记 常用命令 设置docker开机自启:sudo chkconfig docker on 查所有镜像: docker images 删除某个镜像:docker rmi CONTAINER ...

  4. 【Git+Docker】Docker初期学习认识和安装配置详解

    Docker: 特性: 1.以应用为中心 2.自动化构建 3.版本控制 4.组件重用 5.镜像共享 6.工具生态系统 具体后续学习 优势: 1.文件系统隔离 2.进程隔离 3.网络隔离 4.资源隔离和 ...

  5. Docker 0x06: Docker Volume卷

    目录 Docker Volume卷 一句话什么是docker volume? docker volume特性 docker 挂载卷 docker 多容器间共享数据券 删除,查看数据卷 备份还原数据卷 ...

  6. Dockerfile & Docker Swarm & Docker Stack & Docker Compose

    Dockerfile 通俗地讲,它是为了指导单个镜像从无到有的构建过程.如果你镜像是从Docker registry上面拉下来的,那就用不到这个文件:如果你是自己的应用,想打包成镜像,那就需要这个文件 ...

  7. Docker - 命令 - docker volume

    概述 docker volume 命令 背景 docker 容器的存储, 通常需要独立于镜像 docker volume 就是负责这块的命令 1. 写在 docker volume 之前 概述 doc ...

  8. Jenkins在Pod中实现Docker in Docker并用kubectl进行部署

    Jenkins在Pod中实现Docker in Docker并用kubectl进行部署 准备工作 安装Jenkins Jenkins的kubernetes-plugin使用方法 说明 Jenkins的 ...

  9. 【Docker】docker /var/lib/docker/aufs/mnt 目录满了,全是垃圾数据,咋搞?

    命令: #!/bin/bash # 推荐方式 docker volume ls -f dangling=true | awk '{ print $2 }' | xargs docker volume ...

随机推荐

  1. go channel实现

    go channel实现 Go语言经过多年的发展,于最近推出了第一个稳定版本.相对于C/C++来说,Go有很多独特之出,比如提供了相当抽象的工具,如channel和goroutine.本文主要介绍ch ...

  2. npm更新方法

    今天npm的版本更新发现小于3.0 尝试了npm install npm -g 安装么有成功换成了 cnpm install npm -g安装之后就可以

  3. ES6--基础语法(一)

    一.支持环境:node.js完全支持,标准浏览器完全支持.二.测试环境: chrome下需要在script标签的最先开始的地方需要添加"use strict". firefox下需 ...

  4. c# 用代码来设置程序的PrivatePath

    原文:c# 用代码来设置程序的PrivatePath 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/sweety820/article/detail ...

  5. CodeForcesGym 100502H Clock Pictures

    Clock Pictures Time Limit: 1000ms Memory Limit: 524288KB This problem will be judged on CodeForcesGy ...

  6. 高速数论变换(NTT)

    今天的A题.裸的ntt,但我不会,于是白送了50分. 于是跑来学一下ntt. 题面非常easy.就懒得贴了,那不是我要说的重点. 重点是NTT,也称高速数论变换. 在非常多问题中,我们可能会遇到在模意 ...

  7. ubuntu-查看iso文件的md5

    直接使用命令md5sum +文件名就可以了.例如 md5sum ~/YLMF_GHOSTWIN7SP1_X86_YN2015.iso 执行结果如下 cdbb7fdc8bbc30e5e0a398f71b ...

  8. 2.2 Consumer API官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 2.2 Consumer API 2.2.消费者API 随着0..0版本,我们已经增 ...

  9. mysql 压力测试之批量插入自增字段不连续问题

    Gaps in auto-increment values for “bulk inserts” With innodb_autoinc_lock_mode set to 0 (“traditiona ...

  10. httpurlconnection发送文件到服务端并接收

    httpurlconnection发送文件到服务端并接收 客户端 import java.io.DataInputStream; import java.io.File; import java.io ...