I am trying to create and start a Docker container programmatically. The commands succeed but the container dies

146 views Asked by At

Using the Docker.Dotnet SDK, and using an image that succeeds when created via Docker Compose, I create and start the container, get no warnings or errors, but then I see the container 'exited' right away. I am looking for the minimal code needed to create and start a container via the Docker API (with any SDK or just the end points). Thanks

            var exposedPorts = new Dictionary<string, EmptyStruct>();
            exposedPorts.Add(recorderHttpPort, new EmptyStruct());

            var createResponse = await client.Containers.CreateContainerAsync(new CreateContainerParameters()
            {
                Image = recorderImage.ID,
                Name = containerName,
                ExposedPorts = exposedPorts,
                HostConfig = new HostConfig()
                {
                    DNS = new[] { $"0.0.0.0:{recorderHttpPort}" }
                }
            }); ;
1

There are 1 answers

0
Reuben Sivan On

Just figured out that needed to add an entry point: "tail -f /dev/null". The container now finally starts.