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
Newsletter
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

  • How an AI Software Factory Works: From Developer Intent to Production
  • Avoiding AI Debt as a Team
  • The Three Tiers of Agentic Incident Response: When to Trust AI Autonomy
  • AI Agents Need an Identity Plane: Rethinking Enterprise Authorization for Autonomous Software

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
DZone Core CORE ·
Jun. 27, 19 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
38.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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