stkvtflw
stkvtflw

Reputation: 13587

How do I pass arguments to docker run in a CLI (Command Line Interface)?

I need my image to start with this command:

docker run -it --rm --security-opt seccomp=./chrome.json <image_id>

I'm deploying it to Google Compute Engine: https://cloud.google.com/compute/docs/containers/deploying-containers

As far as I understand, I can't specify arguments there, so Google Cloud starts it with just docker run command.

How do I pass these arguments? Maybe I can specify those args in Dockerfile somehow?

Upvotes: 2

Views: 1550

Answers (1)

guillaume blaquiere
guillaume blaquiere

Reputation: 76000

When you use the feature to deploy container directly on Compute Engine, you are limited to the definition of

  • Entry point
  • Args to pass at the entry point
  • Environment variables

That's all, you can't add additional/custom params.

One solution is, instead of using the built in feature, to use the container-optimized OS (COS) on your Compute Engine and to create a startup script to download and run the container with the docker args that you want

METADATA=http://metadata.google.internal/computeMetadata/v1
SVC_ACCT=$METADATA/instance/service-accounts/default
ACCESS_TOKEN=$(curl -H 'Metadata-Flavor: Google' $SVC_ACCT/token | cut -d'"' -f 4)
docker login -u oauth2accesstoken -p $ACCESS_TOKEN https://gcr.io
docker run … gcr.io/your-project/your-image

On the latest line, you can customize the run param in your startup script.

So now, for the update, you have to update the startup script and to reset your VM (or to create a new Compute Engine with COS and the new startup script; and to delete the previous one).

It's matter of tradeoff between the convenience of a built in feature and the customization capacity.

Upvotes: 5

Related Questions