Docker apart form serving our workloads efficiently is also an amazing tool when it comes to not installing additional binaries to your workstation.
Eventually you will find it very easy and simple to just run only one command on docker.
For example I want to run a hello world in go.
My source code is going to be the simple hello world.
package main
import "fmt"
func main() {
fmt.Println("hello world")
}Pretty simple! The file shall be named hello_world.go
Now letβs run this in a container.
docker run -v $(pwd):/go/src/app --rm --name helloworld golang:1.8 go run src/app/hello_world.go
How about installing some go packages and the run our application in one liner?
If you try to do so, you shall realise that docker wonβt interpret the commands the way you want, thus heresβ s how to get the result that you want.
If your image contains the /bin/bash or bin/sh binary you can pass the commands you wan to execute as a string.
docker run -v $(pwd):/go/src/app --rm --name helloworld golang:1.8 /bin/bash -c "cd src/app;go get https:yourpackage;go run src/app/hello_world.go
Thatβs it! Now you can run complex bash one-liners without worrying on installing additional software on your workstations
Published on Java Code Geeks with permission by Emmanouil Gkatziouras, partner at our JCG program. See the original article here: Pass multiple commands on Docker run Opinions expressed by Java Code Geeks contributors are their own. |
Thank you!
We will contact you soon.
Emmanouil GkatziourasJune 27th, 2019Last Updated: June 25th, 2019

This site uses Akismet to reduce spam. Learn how your comment data is processed.