Dag Høidahl
Dag Høidahl

Reputation: 8345

Rename docker machine

How can I rename a docker-machine machine? I can't find it using docker-machine --help or in the subcommand docs.

Upvotes: 21

Views: 11789

Answers (5)

Alberto
Alberto

Reputation: 73

I followed the following steps for docker-compose with VirtualBox in Mac OSX

  1. Rename the virtual machine from VirtualBox console. (I suppose that you could also use vboxmanage modifyvm "$OLD_MACHINE_NAME" --name "$NEW_MACHINE_NAME")
  2. Remove the virtual machine from VirtualBox console. Be aware of not removing the data, only the virtual machine.
  3. Go to VirtualBox Media Manager and remove the Hard disks and Optical disks used by the machine that has been removed. (It is needed to import the virtual machine later)
  4. Rename the directory for the virtual machine in docker directory. Usually in $HOME/.docker/machine/machines. mv $OLD_MACHINE_NAME $NEW_MACHINE_NAME
  5. Replace all references to the old machine name in the config.json, that is in the machine directory, with the new machine name. As I was renaming a machine to default, in my case it was $HOME/.docker/machine/machines/default/config.json
  6. Update the directories pointing to the disk Images in the .vbox file that is in a subdirectory of the virtual machine directory. You must ensure that they are pointing to the new location. (In my case it was $HOME/.docker/machine/machines/default/default/default.vbox)
  7. Import back the virtual machine to VirtualBox with the Machine > Add... option from the menu. Choose the .vbox file that is in the subdirectory of the machine directory. (In my case it was $HOME/.docker/machine/machines/default/default/default.vbox)

I'm using the following versions: docker-machine version 0.13.0, build 9ba6da9 Virtual Box Version 5.2.6 r120293

Upvotes: 1

Sarah
Sarah

Reputation: 1

If you use docker toolbox to create or start docker machine ,there is a script file to config machine settings including name. Find your docker toolbox path like:c:\Program Files\Docker Toolbox. There is a script named start.sh .replace default name as your machine's name.

VM=${DOCKER_MACHINE_NAME-xxxxx}

It is better to remove your default machine files before change config. Then restart toolbox.

Upvotes: 0

Alex Proca
Alex Proca

Reputation: 487

Basically you have to:

  1. rename the directory of your docker-machine from docker machine store (usually in /.docker/machine/machines/ )
  2. update config.json with the new name and new path
  3. rename machine in the virtual machine provider (VirtualBox, VMware, etc.)

Here is a gist for VirtualBox. With this you can rename machines like this docker-machine-rename default my-default

This will only work if you are using VirtualBox. If you are using paralells driver or something else you have to replace vboxmanage ... with the appropriate command for that driver

EDITED I updated the script after receiving feedback from @DagHøidahl

Upvotes: 14

DerekC
DerekC

Reputation: 842

!! WARNING: The method I used below did not work !!

In the final restart I had a client version mismatch. After closing the terminal and restarting the "Docker Quickstart Terminal" my default machine was deleted and re-created... :(

Anyway, for those who might be able point out any error in the process - I've listed it here.

Perhaps the name 'default' is reserved. For the moment I am sticking with the name 'vm' for the machine hosted in VMWare Fusion

I've posted this non-answer as a warning for anyone who might try the same and lose any containers in the default machine.


Goal: delete the default machine and rename vm to default. Then use the new machine as default

The method I used is not elegant, and [in the end] did not work for me...

  1. remove docker-machine

    docker-machine rm default

  2. rename directory

    cd ~/.docker/machine/machines
    mv vm default
    cd default

  3. manually rename all the vm.* files to default.*

    mv vm.plist default.plist
    mv vm.vmdk default.vmdk
    mv vm.vmdk.lck default.vmdk.lck
    mv vm.vmsd default.vmsd
    mv vm.vmx default.vmx
    mv vm.vmx.lck default.vmx.lck
    mv vm.vmxf default.vmxf

  4. edit the default.vmx and replace vm with default in the appropriate places

    [you need to do this yourself...]

  5. open the new 'default' VM in VMWare Fusion
    • Finder -> go -> folder -> ~/.docker/machine/machines
    • Drag the .vmx file into Fusion
  6. Start the renamed machine

    $ docker-machine start default
    Starting "default"...
    Machine "default" was started.
    Waiting for SSH to be available...
    Detecting the provisioner...
    Started machines may have new IP addresses. You may need to re-run the docker-machine env command.
    $ docker-machine env
    Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "172.16.41.132:2376": x509: certificate is valid for 172.16.41.131, not 172.16.41.132
    You can attempt to regenerate them using docker-machine regenerate-certs [name].
    Be advised that this will trigger a Docker daemon restart which will stop running containers.
    $ docker-machine regenerate-certs default
    Regenerate TLS machine certs? Warning: this is irreversible. (y/n): y
    Regenerating TLS certificates
    Waiting for SSH to be available...
    Detecting the provisioner...
    Copying certs to the local machine directory...
    Copying certs to the remote machine...
    Setting Docker configuration on the remote daemon...

At this point the machine worked fine... however, attempting another docker-machine restart default produced a client version mismatch error.

After closing the terminal and restarting "Docker Quickstart Terminal" the default machine was regenerated using the virtualbox and my VMWare hosted default machine was deleted...

Upvotes: -2

Woot4Moo
Woot4Moo

Reputation: 24316

Looks like there was a pull request that was abandoned: PR 30

In related issues, there is debate about not allowing this command: Issue 59

Upvotes: 12

Related Questions