docker 常用命令

在virtualbox上面创建虚拟机

docker-machine create --driver virtualbox myvm1 

在hyperv中创建虚拟机

docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm1 # Win10

绑定你的shell到虚拟机

docker-machine env myvm1                # View basic information about your node

列出集群中的节点:

docker-machine ssh myvm1 "docker node ls"         # List the nodes in your swarm

查看节点的信息:

docker-machine ssh myvm1 "docker node inspect <node ID>"        # Inspect a node

查看Swarm的token:在添加Worker的到集群的时候会用到

docker-machine ssh myvm1 "docker swarm join-token -q worker"   # View join token

通过ssh连接到虚拟机,通过exit命令退出

docker-machine ssh myvm1   # Open an SSH session with the VM; type "exit" to end

登陆到虚拟机上后使用,列出集群下面的节点

docker node ls                # View nodes in swarm (while logged on to manager)

将Worker移除集群

docker-machine ssh myvm2 "docker swarm leave"  # Make the worker leave the swarm

Swarm管理机离开集群,并且解散集群

docker-machine ssh myvm1 "docker swarm leave -f" # Make master leave, kill swarm

查看所有docker虚拟机,‘*’代表当前shell连接的虚拟机

docker-machine ls # list VMs, asterisk shows which VM this shell is talking to

开启docker虚拟机

docker-machine start myvm1            # Start a VM that is currently not running

建立当前主机和docker虚拟机的shell关联

docker-machine env myvm1      # show environment variables and command for myvm1

eval $(docker-machine env myvm1)         # Mac command to connect shell to myvm1

部署应用到集群

docker stack deploy -c <file> <app>  # Deploy an app; command shell must be set to talk to manager (myvm1), uses local Compose file

本机拷贝文件到docker虚拟机

docker-machine scp docker-compose.yml myvm1:~ # Copy file to node's home dir (only required if you use ssh to connect to manager and deploy the app)

在本机部署应用到docker虚拟机集群

docker-machine ssh myvm1 "docker stack deploy -c <file> <app>"   # Deploy an app using ssh (you must have first copied the Compose file to myvm1)

取消本机和虚拟机的shell关联

eval $(docker-machine env -u)     # Disconnect shell from VMs, use native docker

停止所有虚拟机:

docker-machine stop $(docker-machine ls -q)               # Stop all running VMs

删除所有虚拟机和虚拟机残留文件

docker-machine rm $(docker-machine ls -q) # Delete all VMs and their disk images
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值