Search code examples
dockervirtual-machinedocker-swarmdocker-stack

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.

the teacher connects to a VM of the swarm and then deploys a docker stack from this directory docker@node1:~/srv/swarm-stack-1:

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.

How can I find out where is docker@node1 located in my 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 ?

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.

# 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.

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 ?


Solution

  • SOLVED

    The solution here is not to ssh into the VM, and instead to change to the VM context with:

    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.

    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 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)