containers / podman

Podman: A tool for managing OCI containers and pods.
https://podman.io
Apache License 2.0
23.45k stars 2.38k forks source link

Volume is not created when using VOLUME in Dockerfile #2170

Closed tvass closed 5 years ago

tvass commented 5 years ago

/kind bug

Podman does NOT create a volume at run when it is specified in the Dockerfile.

Steps to reproduce the issue:

  1. Create a basic Dockerfile that use VOLUME syntax.
    FROM ubuntu
    RUN mkdir /myvol
    RUN echo "hello world" > /myvol/greeting
    VOLUME /myvol
  2. Build
    $ buildah bud -t test .
    STEP 1: FROM ubuntu
    STEP 2: RUN mkdir /myvol
    STEP 3: RUN echo "hello world" > /myvol/greeting
    STEP 4: VOLUME /myvol
    STEP 5: COMMIT containers-storage:[overlay@/home/tvass/.local/share/containers/storage+/run/user/1000:overlay.mount_program=/usr/bin/fuse-overlayfs,overlay.mount_program=/usr/bin/fuse-overlayfs]localhost/test:latest
    Getting image source signatures
    Skipping fetch of repeat blob sha256:2fb7bfc6145d0ad40334f1802707c2e2390bdcfc16ca636d9ed8a56c1101f5b9
    Skipping fetch of repeat blob sha256:c8dbbe73b68c96e3252f8191226b700d4f4b284154624fa40a2e6a0c42712a0d
    Skipping fetch of repeat blob sha256:1f6b6c7dc482cab1c16d3af058c5fa1782e231cac9aab4d9e06b3f7d77bb1a58
    Skipping fetch of repeat blob sha256:2c77720cf318a4c7eaee757162e6bfc364c3ed83a96a525bc20c548e0f75f1af
    Copying blob sha256:c6d18d2f24e2942cdf5fabb4c8cd06202fb3f559fa6e57a8d1996e236299a798
    152 B / 152 B [============================================================] 0s
    Copying config sha256:8410741373f6544ba90712f8e3faada622526ae444d870288d50bbb10f4983ef
    2.56 KiB / 2.56 KiB [======================================================] 0s
    Writing manifest to image destination
    Storing signatures
    --> 8410741373f6544ba90712f8e3faada622526ae444d870288d50bbb10f4983ef
  3. Run
    podman run --rm -ti test sh
    # 

    On a separate terminal, check volumes present : Describe the results you received:

$ podman volume ls
DRIVER   VOLUME NAME
$

Describe the results you expected: We should have a volume.

$ podman volume ls
DRIVER   VOLUME NAME
local    xxxxxxxxxxxxxxxxxxxxxxxxxx
$

Additional information you deem important (e.g. issue happens only occasionally): Could you please tell me if this is expected or a bug ? Thanks

Output of podman version:

podman version 0.12.1.2

Output of podman info:

podman info
host:
  BuildahVersion: 1.6-dev
  Conmon:
    package: podman-0.12.1.2-1.git9551f6b.fc29.x86_64
    path: /usr/libexec/podman/conmon
    version: 'conmon version 1.12.0-dev, commit: 67ab7549b44484cc3f201d7bb2b58b922f8edc24'
  Distribution:
    distribution: fedora
    version: "29"
  MemFree: 6490259456
  MemTotal: 16450523136
  OCIRuntime:
    package: runc-1.0.0-66.dev.gitbbb17ef.fc29.x86_64
    path: /usr/bin/runc
    version: |-
      runc version 1.0.0-rc6+dev
      commit: ead425507b6ba28278ef71ad06582df97f2d5b5f
      spec: 1.0.1-dev
  SwapFree: 8296329216
  SwapTotal: 8296329216
  arch: amd64
  cpus: 8
  hostname: dhcp-10-17-17-222.yul.redhat.com
  kernel: 4.19.14-300.fc29.x86_64
  os: linux
  rootless: true
  uptime: 4h 54m 21.87s (Approximately 0.17 days)
insecure registries:
  registries: []
registries:
  registries:
  - docker.io
  - registry.fedoraproject.org
  - quay.io
  - registry.access.redhat.com
  - registry.centos.org
store:
  ContainerStore:
    number: 1
  GraphDriverName: overlay
  GraphOptions:
  - overlay.mount_program=/usr/bin/fuse-overlayfs
  - overlay.mount_program=/usr/bin/fuse-overlayfs
  GraphRoot: /home/tvass/.local/share/containers/storage
  GraphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
  ImageStore:
    number: 20
  RunRoot: /run/user/1000

Additional environment details (AWS, VirtualBox, physical, etc.): Fedora 29

mheon commented 5 years ago

I believe our default driver for image volumes is to create per-container persistent directories, for which this would be the expected behavior. We don't presently support named volumes for image volumes, but I don't believe it would be that hard to implement.

We should check what the default behavior in Docker is and reference that.

rhatdan commented 5 years ago

We should be creating that. @umohnani8 PTAL @tvass could you see if this is fixed in podman 1.0?

tvass commented 5 years ago

@rhatdan tl;dr Does NOT work with podman 1.0.

Version check:

$ /home/tvass/go/src/github.com/containers/libpod/bin/podman version
Version:       1.0.1-dev
Go Version:    go1.11.4
Git Commit:    "ab4eea6e9ba7419ee6975afbc1a71ed55984df5a"
Built:         Thu Jan 17 09:12:52 2019
OS/Arch:       linux/amd64

Check if a volume is present in container spec:

$ /home/tvass/go/src/github.com/containers/libpod/bin/podman inspect test
[...]
            "Volumes": {
                "/myvol": {}
            }
[...]

Run test:

$ /home/tvass/go/src/github.com/containers/libpod/bin/podman run  --rm -ti test sh
#

Check if volume is present on a separate terminal:

$ /home/tvass/go/src/github.com/containers/libpod/bin/podman volume ls
$
rhatdan commented 5 years ago

Is myvolume present within a container you run?

tvass commented 5 years ago

Yes.

root@d3e805e8aea1:/# ls -la /myvol
total 12
drwxrwxrwx.  2 root root 4096 Jan 24 19:05 .
drwxr-xr-x. 22 root root 4096 Jan 24 19:05 ..
-rw-rw-rw-.  1 root root   12 Jan 24 19:04 greeting
mheon commented 5 years ago

This is working as intended given the current image code. We don't yet have support for making volumes for image volumes. Probably would not be difficult if we wanted to add it.

rhatdan commented 5 years ago

Works fine for Root podman.

# cat /tmp/Dockerfile 
FROM ubuntu
RUN mkdir /myvol
RUN echo "hello world" > /myvol/greeting
VOLUME /myvol
# podman build -f /tmp/Dockerfile -t test1 /tmp/
STEP 1: FROM ubuntu
STEP 2: RUN mkdir /myvol
--> Using cache 35ad63b1e0d931ead9ba58f55bd0f3d0b147656aeb9e88c9d3b79740e4ebc61c
STEP 3: FROM 35ad63b1e0d931ead9ba58f55bd0f3d0b147656aeb9e88c9d3b79740e4ebc61c
STEP 4: RUN echo "hello world" > /myvol/greeting
--> Using cache bdc60823df53227d380ac602ee05a1c0273e92039b61c21849fb04c7c9e97249
STEP 5: FROM bdc60823df53227d380ac602ee05a1c0273e92039b61c21849fb04c7c9e97249
STEP 6: VOLUME /myvol
--> Using cache 5b6ce2f0c882d841b9e6bc01179c73aab2b6388d3a78aa68504e1720f73ec712
STEP 7: COMMIT test1
# podman run test1 ls /myvol
greeting

Also works for rootless.

$ podman build -f /tmp/Dockerfile -t test1 /tmp/
STEP 1: FROM ubuntu
Getting image source signatures
Copying blob 38e2e6cd5626: 30.80 MiB / 30.80 MiB [=========================] 55s
Copying blob 705054bc3f5b: 849 B / 849 B [=================================] 55s
Copying blob c7051e069564: 517 B / 517 B [=================================] 55s
Copying blob 7308e914506c: 164 B / 164 B [=================================] 55s
Copying config 20bb25d32758: 3.32 KiB / 3.32 KiB [==========================] 0s
Writing manifest to image destination
Storing signatures
STEP 2: RUN mkdir /myvol
--> 51f0247eed9cfad2c42e19a1933efc35b7ca7c14457550a43e304ca59715d9af
STEP 3: FROM 51f0247eed9cfad2c42e19a1933efc35b7ca7c14457550a43e304ca59715d9af
STEP 4: RUN echo "hello world" > /myvol/greeting
--> 567163a2024f25a247d8fa9ed773e84f2febb6b9708e015845791d8e28991e45
STEP 5: FROM 567163a2024f25a247d8fa9ed773e84f2febb6b9708e015845791d8e28991e45
STEP 6: VOLUME /myvol
--> 1315c2bf9a3d3f76ed4e61237487c84d67cfe413209c25659a93353eda7e6482
STEP 7: COMMIT test1
$ podman run test1 ls /myvol
greeting

podman -v podman version 1.0.0

rhatdan commented 5 years ago

Ok, I see it now, this volume is not listed under podman volume though.

umohnani8 commented 5 years ago

@rhatdan with podman build, buildah bud is doing all the work and we don't have the volumes support in buildah yet. I think that is why the volume is not being created under the path that podman volume checks for any volumes created. I believe something we have to add.

rhatdan commented 5 years ago

I found a bunch of bogs on podman volumes and have opened a PR on this.

Lots of fixes in https://github.com/containers/libpod/pull/2229

rhatdan commented 5 years ago

This is fixed in master.