Skip to content

How to execute command on running container? #225

Answered by mariotoffia
PugachA asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @PugachA, you can run a command on a container using the Execute command.

💡 Below sample will output: The command was executed successfully:

using (
    var container =
        new Builder().UseContainer()
            .UseImage("postgres:9.6-alpine")
            .ExposePort(5432)
            .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
            .WaitForPort("5432/tcp", 30000)
            .Build()
            .Start())
{

  var config = container.GetConfiguration(true);

  // Run the *echo* command inside the running container
  var output = container.DockerHost.Execute(
                                config.Id,
                                "echo \"I'm inside the container

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by PugachA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants