<p>docker engine supports <a href="https://docs.docker.com/storage/volumes/#remove-volumes" rel="nofollow noreferrer">data volumes</a></p>
<blockquote>
<p>A Docker data volume persists after a container is deleted</p>
</blockquote>
<p><a href="https://docs.docker.com/engine/reference/commandline/run/#mount-volume--v---read-only" rel="nofollow noreferrer"><code>docker run</code></a> and <a href="https://docs.docker.com/compose/compose-file/#volumes" rel="nofollow noreferrer"><code>docker-compose</code></a> both support it:</p>
<ol>
<li><code>docker run --volume data_vol:/mount/point</code></li>
<li>docker-compose with named volumes using top-level <code>volumes</code> key</li>
</ol>
<p>kubernetes also supports <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">persistent volumes</a>, but <strong>does it support the same concept of having a data volume - that is, a volume which resides within a container?</strong></p>
<p>if kubernetes supports a data volume (within a container):</p>
<ol>
<li>would appreciate any reference to the documentation (or an example)</li>
<li>does it also support the migration of the data volume in the same manner it supports the migration of regular containers?</li>
</ol>
<p>i found some <a href="https://stackoverflow.com/questions/53062547/docker-volume-vs-kubernetes-persistent-volume">related questions</a>, but couldn't get the answer i am looking for.</p>

Mr.
<p>What you are trying to say is:</p>
<p>If you do not specify a host path for a docker volume mount, docker dynamically provisions a path and persist it between restarts.</p>
<p><strong>&quot;that is, a volume which resides within a container&quot;</strong>
Volume is generated outside of container and mounted later.</p>
<p>For example:</p>
<pre class="lang-sh prettyprint-override"><code># data_vol location is decided by docker installation
docker run --volume data_vol:/mount/point

# host path is explicitly given
docker run --volume /my/host/path:/mount/point
</code></pre>
<p>In kubernetes terms, this is similar to dynamic provisioning. If you want dynamic provisioning, you need to have Storage classes depending on your storage backend.</p>
<p>Please read <a href="https://kubernetes.io/docs/concepts/storage/dynamic-provisioning/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/dynamic-provisioning/</a> .</p>
<p>If you want to specify a host path, following is an example. You can also achieve similar results by using NFS, block storage etc.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 10Gi
  hostPath:
    path: /home/user/my-vol
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: my-ss
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-ss
  serviceName: my-svc
  template:
    metadata:
      labels:
        app: my-ss
    spec:
      containers:
        - image: ubuntu
          name: my-container
          volumeMounts:
            - mountPath: /my-vol
              name: my-vol
  volumeClaimTemplates:
    - metadata:
        name: my-vol
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 10Gi
        selector:
          matchLabels:
            app: my-ss
</code></pre>
