I need to connect to windows remote server(shared drive) from GO API hosted in the alpine linux. I tried using tcp,ssh and ftp none of them didn't work. Any suggestions or ideas to tackle this?
-
What have you tried so far? – Rastalamm Jul 09 '19 at 16:56
-
tcp connection using the ip addess and port – Srikanth Reddy Jul 09 '19 at 18:19
-
`connection, err := net.Dial("tcp", fmt.Sprintf("%s:%d", Host, Port))` `if err != nil {` `log.Fatal("Something went wrong with connection", err)` } if connection == nil { log.Fatal("could not create connection") } defer connection.Close() log.Println("Connected to server")``` – Srikanth Reddy Jul 10 '19 at 01:05
2 Answers
Before proceeding with debugging the GO code, it would be needed to do some "unskilled labour" within container in order to ensure pre-requisites are met:
- samba client is installed and daemons are running;
- the target name gets resolved;
- there are no connectivity issues (routing, firewall rules, etc);
- there are share access permissions;
- mounting remote volume is allowed for the container.
Connect to the container:
$ docker ps
$ docker exec -it container_id /bin/bash
Samba daemons are running:
$ smbd status
$ nmbd status
You use the right name format in your code and command lines:
UNC notation => \\server_name\share_name
URL notation => smb://server_name/share_name
Target name is resolvable
$ nslookup server_name.domain_name
$ nmblookup netbios_name
$ ping server_name
Samba shares are visible
$ smbclient -L //server [-U user] # list of shares
and accessible (ls
, get
, put
commands provide expected output here)
$ smbclient //server/share
> ls
Try to mount remote share as suggested by @cwadley (mount could be prohibited by default in Docker container):
$ sudo mount -t cifs -o username=geeko,password=pass //server/share /mnt/smbshare
For investigation purposes you might use the Samba docker container available at GitHub, or even deploy your application in it since it contains Samba client and helpful command line tools:
$ sudo docker run -it -p 139:139 -p 445:445 -d dperson/samba
After you get this working at the Docker level, you could easily reproduce this in Kubernetes.
You might do the checks from within the running Pod in Kubernetes:
$ kubectl get deployments --show-labels
$ LABEL=label_value; kubectl get pods -l app=$LABEL -o custom-columns=POD:metadata.name,CONTAINER:spec.containers[*].name
$ kubectl exec pod_name -c container_name -- ping -c1 server_name
Having got it working in command line in Docker and Kubernetes, you should get your program code working also.
Also, there is a really thoughtful discussion on StackOverflow regards Samba topic:
Mount SMB/CIFS share within a Docker container

- 2,495
- 1
- 5
- 9
Windows shares use the SMB protocol. There are a couple of Go libraries for using SMB, but I have never used them so I cannot vouch for their utility. Here is one I Googled:
https://github.com/stacktitan/smb
Other options would be to ensure that the Windows share is mounted on the Linux host filesystem using cifs. Then you could just use the regular Go file utilities:
https://www.thomas-krenn.com/en/wiki/Mounting_a_Windows_Share_in_Linux
Or, you could install something like Cygwin on the Windows box and run an SSH server. This would allow you to use SCP:
-
I have tried ssh connection but it is throwing error **ssh: handshake failed : EOF** . Also, I have tried smb package that you mentioned. `smb` package have the capability to check if we can establish the connection and able to login. But there are no functions to use the session and write file to destination path. – Srikanth Reddy Jul 10 '19 at 00:30