How to configure the env vars , net name, exposed port and volumns when running a docker container in go sdk

0

I'm trying to use the go SDK to run a docker container. In CLI, the docker can be run by

docker run -d \
-e myvar1=myval1 \
-e myvar2=myval2 \
--name=myname \
--hostname=myhost \
--net=mynet \
-p 12345:12345 -p 8080:8080  \
-v "my/path/to/data1"  \
-v "my/second-path/to/data2" \
mydocker/image_name:latest command1 \
command2 \
command3

I wonder how to find the go SDK equivalent for this cli command. I referred to this post but I'm still confused about the setting for env vars, network, columns and also multiple exposed ports.

docker go
2021-11-23 18:29:39
1

0

You have a more complete example with interiorem/stout/isolate/docker/container.go##newContainer() which does set env map[string]string in the old docker/engine-api container.Config structure.
These days, you would use moby/moby/api/types/container/config.go.

But in both cases (old and new dependencies), you set environment variables by initializing a Config struct with a map of "environment name"/"environment value" in the Env field.

2021-11-25 08:02:26

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................