简体   繁体   English

如何在本地虚拟机内复制文件或如何在本地虚拟机内编辑 yml 文件? (码头工人栈)

[英]How to copy files inside a local virtual machine or how to edit a yml file inside a local virtual machine? (docker stack)

I'm following a tutorial on docker stack, swarm, compose, etc.我正在关注关于 docker 堆栈、群、撰写等的教程。

the teacher connects to a VM of the swarm and then deploys a docker stack from this directory docker@node1:~/srv/swarm-stack-1 :老师连接到 swarm 的一个虚拟机,然后从这个目录 docker docker@node1:~/srv/swarm-stack-1部署一个 docker 堆栈:

docker stack deploy -c example-voting-app-stack.yml voteapp

However, I can't get there because I don't know how to copy the yaml compose file from the course repository to the directory inside the VM.但是,我无法到达那里,因为我不知道如何将 yaml 撰写文件从课程存储库复制到 VM 内的目录。

How can I find out where is docker@node1 located in my PC?如何找出docker@node1在我的 PC 中的位置?

Here is what I tryed:这是我尝试过的:

docker-machine start node1 

Docker-machine ssh node1

So I get所以我得到

Tommaso@N552VW-Tommaso MINGW64 /c/Applicazioni_Tommaso/Docker Toolbox
$ Docker-machine ssh node1
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

then然后

docker@node1:~/srv/swarm-stack-1$ pwd
/home/docker

ok then, but where is /home/docker located in my PC?好的,但是/home/docker位于我的 PC 中的哪个位置?

So I tryed to get around the obstacle by creating a yml file inside the VM and then editing it, rather than copying it from another directory.所以我试图通过在虚拟机中创建一个 yml 文件然后编辑它来绕过这个障碍,而不是从另一个目录复制它。

# create the directory
docker@node1:~$ mkdir srv
docker@node1:~$ cd srv
docker@node1:~/srv$ mkdir swarm-stack-1
docker@node1:~/srv$ cd swarm-stack-1
docker@node1:~/srv/swarm-stack-1$

# create the yml file
touch example-voting-app-stack.yml

and here I stop because I don't know how to edit the file.在这里我停下来,因为我不知道如何编辑文件。

I can nor install vim or install a program to install vim.我也无法安装 vim 或安装程序来安装 vim。

This is what I tryed:这是我尝试过的:

docker@node1:~/srv/swarm-stack-1$ vim example-voting-app-stack.yml
-bash: vim: command not found

docker@node1:~/srv/swarm-stack-1$ apt-get vim
-bash: apt-get: command not found
docker@node1:~/srv/swarm-stack-1$ yum install vim
-bash: yum: command not found
docker@node1:~/srv/swarm-stack-1$ apk install vim
-bash: apk: command not found
docker@node1:~/srv/swarm-stack-1$ sudo apt-get install vim
sudo: apt-get: command not found

docker@node1:~/srv/swarm-stack-1$ nano
-bash: nano: command not found

So, can somebody help me to understand how to copy files inside my VM (so finding out what is its path in my PC) or how to install a program to install vim and then install vim inside my VM?那么,有人可以帮助我了解如何在我的 VM 中复制文件(以便找出它在我的 PC 中的路径)或如何安装程序来安装 vim,然后在我的 VM 中安装 vim?

SOLVED解决了

The solution here is not to ssh into the VM, and instead to change to the VM context with:这里的解决方案不是将 ssh 放入 VM,而是更改为 VM 上下文:

docker-machine env node1
eval $(docker-machine env node1)

By doing so, you are in the VM context, so docker node ls and all the swarm commands work, but you still have access to your local files, because you're not in the VM.通过这样做,您处于 VM 上下文中,因此docker node ls和所有 swarm 命令都可以工作,但您仍然可以访问本地文件,因为您不在 VM 中。

So, after running the two lines above, I can finally switch my current directory to the course repo containing the docker-compose file I want to input in the docker stack deploy command, and run:因此,在运行上述两行之后,我终于可以将当前目录切换到包含我想在 docker 堆栈部署命令中输入的 docker-compose 文件的课程存储库,然后运行:

docker stack deploy -c example-voting-app-stack.yml voteapp

When you are done, to change the context back to the local machine do:完成后,要将上下文更改回本地计算机,请执行以下操作:

docker-machine env -u
eval $(docker-machine env -u)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM