func runTorContainer(cli *client.Client, ident, imageID, network string) (string, error) { config := &types.ContainerCreateConfig{ Name: ident, Config: &containerTypes.Config{ Image: imageID, }, } resp, err := cli.ContainerCreate(config.Config, config.HostConfig, config.NetworkingConfig, config.Name) if err != nil { return "", err } // TODO: Remove container on failure. for _, warning := range resp.Warnings { log.Warn(warning) } if err := cli.ContainerStart(resp.ID); err != nil { return "", err } // Connect to the network. if err := cli.NetworkConnect(network, resp.ID, nil); err != nil { return "", err } return resp.ID, err }
// ConnectOnionNetwork connects a target container to the onion network, allowing // the container to be accessed by the Tor relay container. func ConnectOnionNetwork(cli *client.Client, target, network string) error { // XXX: Should configure this to use a subnet like 10.x.x.x. options := &networkTypes.EndpointSettings{} return cli.NetworkConnect(network, target, options) }