how to specify sync-mode and network type while creating docker container using docker go pkg in Golang application?


I am trying to create docker container from my golang application using Docker Engine SDKs and Docker API

this is the command i want to implement in my application:

docker run --name rinkeby-node ethereum/client-go --rinkeby --syncmode full

this is the code i am using

    ctx := context.Background()
    cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
    if err != nil {
    imageName := "ethereum/client-go"
    out, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{})
    if err != nil {
    defer out.Close()
    io.Copy(os.Stdout, out)

    resp, err := cli.ContainerCreate(ctx, &container.Config{
        Image: imageName,
    }, nil, nil, nil, "containerName")
    if err != nil {

    if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {

now i want to specify the syncmode to full and the network to rinkeby


The --syncmode full and --rinkeby flags are the CMD arguments.

So when calling you’re calling ContainerCreate method inside of container.Config add this:

Cmd: []string{"--syncmode", "full", "--rinkeby"}

For a complete example see this

Answered By – mehdy

Answer Checked By – Cary Denson (GoLangFix Admin)

Leave a Reply

Your email address will not be published.