Closed giordano closed 2 years ago
Wait, is that because the first mapping is read-only?
Nevermind, the problem wasn't with the read-only layer, but with internet connectivity. Adapting this snippet from the tests https://github.com/staticfloat/Sandbox.jl/blob/f484672e5b5f3aff2e30b56821c18fd3d3e5d581/test/Sandbox.jl#L303-L308 does the trick:
using Sandbox
mktempdir() do rw_dir
ro_mappings = Dict(
"/" => Sandbox.alpine_rootfs(),
)
# Mount in `/etc/resolv.conf` as a read-only mount if using a UserNS executor, so that we have DNS
if isfile("/etc/resolv.conf")
resolv_conf = joinpath(rw_dir, "resolv.conf")
cp("/etc/resolv.conf", resolv_conf; follow_symlinks=true)
ro_mappings["/etc/resolv.conf"] = resolv_conf
end
config = SandboxConfig(
ro_mappings;
)
with_executor() do exe
run(exe, config, `/sbin/apk add grep`)
end
end
For the record, the Debian image ships /etc/resolv.conf
by default:
julia> config = SandboxConfig(
Dict("/" => Sandbox.debian_rootfs());
);
julia> with_executor() do exe
run(exe, config, `/usr/bin/cat /etc/resolv.conf`)
end;
nameserver 1.1.1.1
nameserver 8.8.8.8
so it isn't necessary to copy over our /etc/resolv.conf
file to make installation of packages work there.