Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this is the code i am using

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


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

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

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading