I can't use github.com/docker/cli/cli/connhelper connection is established
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 2.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
This is my code
import (
"context"
"fmt"
"github.com/docker/cli/cli/connhelper"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"net/http"
)
func authentication() (cli *client.Client){
helper, err := connhelper.GetConnectionHelper("ssh://root@192.168.56.101:22")
if err != nil {
fmt.Println("Unable helper"+err.Error())
}
httpClient := &http.Client{
Transport: &http.Transport{
DialContext: helper.Dialer,
},
}
c, err := client.NewClientWithOpts(
client.WithHTTPClient(httpClient),
client.WithHost(helper.Host),
client.WithDialContext(helper.Dialer),
)
if err != nil {
fmt.Println("Unable to create docker client"+err.Error())
return c
}
return c
}
func listImage()(images []types.ImageSummary) {
var cli *client.Client
//ctx := context.Background()
cli= authentication()
images, err := cli.ImageList(context.Background(), types.ImageListOptions{})
if err !=nil{
fmt.Println(err.Error())
return images
}
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
fmt.Println(containers)
}
for _, image := range images {
fmt.Println(image)
}
return images
}
The Docker configuration on my host looks like this :
/usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket
[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --registry-mirror=http://hub-mirror.c.163.com
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
KillMode=process
[Install]
WantedBy=multi-user.target
~
~
### As you can see in the code Docker does not open the remote TCP connection port, that is because I understand that connHelper is using SSH connections to set up the CLI
I also have a question why do not need to enter the password
I use Windows development, Windows does not install Docker, connect to the remote server
I don't know what else I need to set or am I writing it wrong? Please give guidance thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Go example using connhelper.GetConnectionHelper and compare it with the Docker systemd service configuration shown in the issue. Reproduce the SSH connection from the Windows development environment and capture the actual client or ImageList error. Done means the expected authentication and remote Docker connection behavior is documented or the underlying connection defect is isolated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- cli, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100