/// <inheritdoc /> protected override async Task ConfigureAsync() { await base.ConfigureAsync(); WaitStrategy = new ExposedPortsWaitStrategy(new List <int> { RyukPort }); ExposedPorts.Add(RyukPort); var dockerHostPath = (Environment.GetEnvironmentVariable("DOCKER_HOST"), Environment.GetEnvironmentVariable("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE")) switch { ({ } s, _)when !string.IsNullOrEmpty(s) => new Uri(s).PathAndQuery, (null, { } s)when !string.IsNullOrEmpty(s) => s, _ => "/var/run/docker.sock" }; BindMounts.Add(new Bind { // apparently this is the correct way to mount the docker socket on both windows and linux // mounting the npipe will not work HostPath = dockerHostPath, // ryuk is a linux container, so we have to mount onto the linux socket ContainerPath = "/var/run/docker.sock", AccessMode = AccessMode.ReadOnly }); AutoRemove = true; }
/// <inheritdoc /> protected override async Task ConfigureAsync() { await base.ConfigureAsync(); WaitStrategy = new ExposedPortsWaitStrategy(new List <int> { RyukPort }); ExposedPorts.Add(RyukPort); BindMounts.Add(new Bind { HostPath = DockerClient.Configuration.EndpointBaseUri.AbsolutePath, ContainerPath = DockerClient.Configuration.EndpointBaseUri.AbsolutePath, AccessMode = AccessMode.ReadOnly }); AutoRemove = true; }
private CreateContainerParameters ApplyConfiguration() { var config = new Config { Image = DockerImageName, Env = Env.Select(kvp => $"{kvp.Key}={kvp.Value}").ToList(), ExposedPorts = ExposedPorts.ToDictionary( e => string.Format(TcpExposedPortFormat, e), e => default(EmptyStruct)), Labels = Labels, WorkingDir = WorkingDirectory, Cmd = Command, Tty = true, AttachStderr = true, AttachStdout = true, }; return(new CreateContainerParameters(config) { HostConfig = new HostConfig { AutoRemove = AutoRemove, PortBindings = PortBindings.ToDictionary( e => string.Format(TcpExposedPortFormat, e.Key), e => (IList <PortBinding>) new List <PortBinding> { new PortBinding { HostPort = e.Value.ToString() } }), Mounts = BindMounts.Select(m => new Mount { Source = m.HostPath, Target = m.ContainerPath, ReadOnly = m.AccessMode == AccessMode.ReadOnly, Type = "bind" }) .ToList(), PublishAllPorts = true, Privileged = IsPrivileged } }); }
/// <inheritdoc /> protected override async Task ConfigureAsync() { await base.ConfigureAsync(); WaitStrategy = new ExposedPortsWaitStrategy(new List <int> { RyukPort }); ExposedPorts.Add(RyukPort); BindMounts.Add(new Bind { // apparently this is the correct way to mount the docker socket on both windows and linux // mounting the npipe will not work HostPath = "//var/run/docker.sock", // ryuk is a linux container, so we have to mount onto the linux socket ContainerPath = "/var/run/docker.sock", AccessMode = AccessMode.ReadOnly }); AutoRemove = true; }