How to transfer files between local machine and minikube?

25.6k Views Asked by At

I am using OS Ubuntu 16.0.4 and i installed minikube on it. I need to copy some files to minikube, so how can i do that? I tried next command but it asked me on password and i don't know it

scp /media/myuser/sourceFolder [email protected]:/home/docker/destiationFolder

Note: minikube IP is 192.168.99.100, and i used docker as default user for minikube but actually i don't know if it correct ot not.

So what is the default username and password for minikube and how can i copy files from my local machine into minikube?

Thanks :)

10

There are 10 best solutions below

4
On BEST ANSWER

I handled it by following next steps:

1- going into ssh of minikube >> minikube ssh

2- Changing docker password using sudo >> sudo passwd docker and create new password so now i know docker user password

3- exit from ssh and go back to Ubuntu terminal >> exit

4- using scp command to copy files into minikube >> scp /local/path/to/file/ docker@minikubeIp:/your/destination/folder/

For example scp -r /media/myuser/sourceFolder [email protected]:/home/docker

and after that it asked only for minikube docker user password which i know it now after changed it then write password and folders copied successfully into minikube from local machine

4
On
4
On

On the host machine you can use the ssh-key and ip subcommands of the minikube command:

scp -i $(minikube ssh-key) <local-path> docker@$(minikube ip):<remote-path>

So the command from the question becomes:

scp -i $(minikube ssh-key) /media/myuser/sourceFolder docker@$(minikube ip):/home/docker/destiationFolder
0
On

Steps to copy required files/folders to minikube machine.

minikube ssh
sudo su root
scp -r <user>@<ip address of linux machine>:<SOURCE FOLDER PATH> <DESTINATION FOLDER PATH>
scp -r [email protected]:/home/userhome/sourfolder /etc/destinationfolder
Enter password of linux machine
0
On

if you have installed minikube Windows Host then you can find the ssh public & private keys for docker user (docker user is in the minikube vm) in

C:\Users\{yourusername}\.minikube\machines\minikube

on Windows Host.

The files are copied by minikube.exe during vm creation.

The files are id_rsa & id_rsa.pub.

Then open the id_rsa in puttygen and save the private key in .ppk format.

After that you can use the newly saved private key with Winscp.

Host name: ip-address of you minikube vm { can get it with c:\minikube ip }

username: docker

port : 22

Go to Advanced ---> Advanced ----> SSH ----> Authentication ---->private key file

Then open...

0
On

On my M1 MacBook, the copying solution from @Drik did not work as expected, while getting some errors like:

ssh: connect to host 192.168.49.2 port 22: Operation timed out lost connection

Sidenote: atm of writing the only way to I was able to run the minikube correctly on AppleSilicon macs is via minikube + docker driver.

I come across this post where @afbjorklund stated.

"Unfortunately Docker Desktop does not offer direct access to the VM, unlike other drivers."

Although there is an option to connect via docker hidden tunneled port.

Solution (minikube + docker driver)

I puzzled all this together and finally managed to copy files also on M1 using minikube + docker driver

$ docker port <CONTAINER_ID>
22/tcp -> 127.0.0.1:58408
2376/tcp -> 127.0.0.1:58409

scp -i $(minikube ssh-key) -P 58408 /media/myuser/sourceFolder [email protected]:/home/docker/destiationFolder
0
On

At minikube 1.7, if using the VirtualBox driver, there exists a /hosthome folder mounted inside the minikube VM. This is a VirtualBox shared folder mapping to /home of the host system.

So, practically, if you ssh to the minikube VM everything from your home folder is readable and you can use normal cp commands to copy things around.

0
On

As som answers have already mentioned, you can mount a local directory onto Minikube: minikube mount <source directory>:<target directory>

This is supremely useful as you can move files in either direction, and use it to easily inspect the outputs of any work done inside Minikube.

0
On

 You can use minikube cp to copy the specified file into minikube.

minikube cp <source file path> <target node name>:<target file absolute path> [flags]

 If you don't know the target node name, you can run minikube node list first to get the node name. More info could be found in the official doc.

0
On

As others have already mentioned, the easiest way would be to -

minicube cp <source-file> <absolute-path/target-file>