admin管理员组文章数量:1200790
I have a Linux operating system (Ubuntu).
I want to run docker-compose on command from the frontend. For this I wrote a service that has access to the docker-compose.yml file. .env file is located in the same directory.
My function:
func runCommand() error {
output, err := exec.Command("/bin/sh", "-c", "docker-compose", "up", "--build", "-d").Output()
if err != nil {
return err
}
c.logger.Info().Msgf("run docker-compose - %s", string(output))
return nil
}
I change the number of replicas in the .env file. And run the function. But it does not work as I want. I tried different command formats, for example:
exec.Command("docker-compose", "up", "--build", "-d")
This command works for me, but only once, the process seems to be held.
I want to execute the command(docker-compose up -d --build
) and reuse the function to handle requests from the frontend.
P.S. After long tests I found that docker-compouse uses an old version of the .env file. Although the .env file changes as a result of the program's operation.
Solution: it turned out that the command exec.Command() uses environment variables from the program for docker-compouse. Forcing the flag --env-file .env for docker-compouse did not give the desired result.
Thanks for any help!
I have a Linux operating system (Ubuntu).
I want to run docker-compose on command from the frontend. For this I wrote a service that has access to the docker-compose.yml file. .env file is located in the same directory.
My function:
func runCommand() error {
output, err := exec.Command("/bin/sh", "-c", "docker-compose", "up", "--build", "-d").Output()
if err != nil {
return err
}
c.logger.Info().Msgf("run docker-compose - %s", string(output))
return nil
}
I change the number of replicas in the .env file. And run the function. But it does not work as I want. I tried different command formats, for example:
exec.Command("docker-compose", "up", "--build", "-d")
This command works for me, but only once, the process seems to be held.
I want to execute the command(docker-compose up -d --build
) and reuse the function to handle requests from the frontend.
P.S. After long tests I found that docker-compouse uses an old version of the .env file. Although the .env file changes as a result of the program's operation.
Solution: it turned out that the command exec.Command() uses environment variables from the program for docker-compouse. Forcing the flag --env-file .env for docker-compouse did not give the desired result.
Thanks for any help!
Share Improve this question edited Jan 21 at 17:42 Михаил Васильев asked Jan 21 at 15:48 Михаил ВасильевМихаил Васильев 436 bronze badges 4 |1 Answer
Reset to default 1P.S. After long tests I found that docker-compouse uses an old version of the .env file. Although the .env file changes as a result of the program's operation.
Solution: it turned out that the command exec.Command() uses environment variables from the program for docker-compouse. Forcing the flag --env-file .env for docker-compouse did not give the desired result.
本文标签: goGolang exec command dockercomposeStack Overflow
版权声明:本文标题:go - Golang exec command docker-compose - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738620331a2103151.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
/bin/sh -c
arguments: they're unnecessary here, cause any options to the command to be lost, and introduce a serious security issue if they're present. If you can run anydocker
command at all, you can all but trivially root the host system, so think carefully about whether you actually need to do this in the program, and if you do, be very careful with anything security-related. – David Maze Commented Jan 21 at 16:32docker compose
, notdocker-compose
(or in this case"docker", "compose"
) – BMitch Commented Jan 21 at 19:04