swarm搭建
安装docker engine
docker-machine create --driver=virtualbox vbox-test
(可以下载boot2docker.iso放到对应目录,再运行此命令,跳过命令的下载过程)
docker-machine启动关闭
docker-machine start vbox-test
docker-machine stop vbox-test
ssh虚拟机
docker-machine ssh vbox-test
设置环境变量
docker-machine env --shell fish vbox-test
--根据提示 执行环境变量设置命令, 如: eval (docker-machine env --shell fish vbox-test)
验证环境变量设置
env | grep DOCKER
[optional] docker-machine env --no-proxy vbox-test
在docker engine上创建运行一个container
docker run busybox echo hello world
build a image, in the path same with Dockerfile
docker build -t george/hello_docker:v1.0 .
docker image ls
run in attach mode
docker run -p 4000:80 george/hello_docker:v1.0
run in detach mode
docker run -d -p 4000:80 george/hello_docker:v1.0
docker container ls
查看docker容器日志
docker logs [OPTIONS] CONTAINER
在宿主上交互式进入container的bash命令行
docker exec -it
在宿主上交互式执行container内的命令
docker exec -it -w /root ubuntu_bash pwd
提交container为image
docker commit
docker container stop
remove a container
docker rm
docker pull
docker swarm init
run a stack
docker stack deploy -c docker-compose.yml firstcompose
get the services
docker service ls
all services associated with the stack
docker stack services firstcompose
the tasks for your service
docker service ps firstcompose_web
view the logs of a service
docker service logs [OPTIONS] SERVICE|TASK
tasks of a stack
docker stack ps firstcompose
update the app, eg: scale the app, etc.
docker stack deploy -c docker-compose.yml firstcompose
Take the app down
docker stack rm firstcompose
Take down the swarm
docker swarm leave --force
创建machine
docker-machine create --driver virtualbox vbox-vm2
查看所有docker machine
docker-machine ls
init and become a manager
docker-machine ssh vbox-vm2 "docker swarm init --advertise-addr <vbox-vm2's ip>"
join as a worker
docker swarm join --token
docker client连到manager
查看所有node
docker node ls
发布app到swarm
docker stack deploy -c docker-compose.yml firstswarmapp
查看swarm上的services
docker stack ps firstswarmapp
Take the app down
docker stack rm firstswarmapp
离开swarm
docker-machine ssh vbox-test "docker swarm leave"
docker-machine ssh vbox-vm2 "docker swarm leave --force"
显示不全,未验证???
sudo docker exec -it -e LINES=$(tput lines) -e COLUMNS=$(tput cols) mysql_1 /bin/bash