DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • A Beginner's Guide to Docker Compose
  • A Beginner's Guide to Essential Commands to Fix Container Setup Issues
  • How To Use the Node Docker Official Image
  • Using Environment Variable With Angular

Trending

  • Swift Concurrency Part 4: Actors, Executors, and Reentrancy
  • The 7 Pillars of Meeting Design: Transforming Expensive Conversations into Decision Assets
  • How to Prevent Data Loss in C#
  • The Invisible OOMKill: Why Your Java Pod Keeps Restarting in Kubernetes
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Pass Multiple Commands on Docker Run

Pass Multiple Commands on Docker Run

This short tutorial demonstrates how Docker can be used to run complex bash commands without additional binaries.

By 
Emmanouil Gkatziouras user avatar
Emmanouil Gkatziouras
DZone Core CORE ·
Jun. 27, 19 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
38.4K Views

Join the DZone community and get the full member experience.

Join For Free

Image title


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 application 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 then run our application in a one-liner?

If you try to do so, you will realise that Docker won't interpret the commands the way you want, so here'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 want 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

Docker (software) Command (computing) Pass (software)

Published at DZone with permission of Emmanouil Gkatziouras. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • A Beginner's Guide to Docker Compose
  • A Beginner's Guide to Essential Commands to Fix Container Setup Issues
  • How To Use the Node Docker Official Image
  • Using Environment Variable With Angular

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook