Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parsing of HostConfig.Mounts for container create #12433

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/podman/common/create_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c
addField(&builder, "type", string(m.Type))
addField(&builder, "source", m.Source)
addField(&builder, "target", m.Target)
addField(&builder, "ro", strconv.FormatBool(m.ReadOnly))
if m.ReadOnly {
addField(&builder, "ro", "true")
}
addField(&builder, "consistency", string(m.Consistency))
// Map any specialized mount options that intersect between *Options and cli options
switch m.Type {
Expand Down
25 changes: 24 additions & 1 deletion test/python/docker/compat/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import sys
import time
import unittest
from typing import IO, Optional
from typing import IO, Optional, List

from docker import DockerClient, errors
from docker.models.containers import Container
from docker.models.images import Image
from docker.models.volumes import Volume
from docker.types import Mount

from test.python.docker import Podman
from test.python.docker.compat import common, constant
Expand Down Expand Up @@ -277,3 +278,25 @@ def test_non_existant_workdir(self):
ctr.start()
ret, out = ctr.exec_run(["stat", "/workspace/scratch/test"])
self.assertEqual(ret, 0, "Working directory created if it doesn't exist")

def test_mount_rw_by_default(self):
ctr: Optional[Container] = None
vol: Optional[Volume] = None
try:
vol = self.client.volumes.create("test-volume")
ctr = self.client.containers.create(image="alpine",
detach=True,
command="top",
mounts=[Mount(target="/vol-mnt",
source="test-volume",
type='volume',
read_only=False)])
ctr_inspect = self.client.api.inspect_container(ctr.id)
binds: List[str] = ctr_inspect["HostConfig"]["Binds"]
self.assertEqual(len(binds), 1)
self.assertEqual(binds[0], 'test-volume:/vol-mnt:rw,rprivate,nosuid,nodev,rbind')
finally:
if ctr is not None:
ctr.remove()
if vol is not None:
vol.remove(force=True)