How to execute command on running container? #225
-
I want execute custom sh commands on running containers. docker exec -it bced6a23bd7f echo "Hello world" I haven't found a way to do this. Can you tell me? |
Beta Was this translation helpful? Give feedback.
Answered by
mariotoffia
Oct 27, 2021
Replies: 1 comment
-
Hi @PugachA, you can run a command on a container using the 💡 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\"",
container.Certificates);
if (output.Data.Contains("I'm inside the container"))
{
Console.WriteLine("The command was executed successfully");
}
else
{
Console.WriteLine("The command was not executed successfully");
}
} Cheers, |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
PugachA
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @PugachA, you can run a command on a container using the
Execute
command.💡 Below sample will output: The command was executed successfully: