docker相关命令学习汇总

docker 命令

#centos安装
yum search docker
yum -y install docker-io
#启动
service docker start

#版本展示
docker --version
docker version
docker info

#查看命令清单
docker --help
docker COMMAND --help
docker container --help

#容器运行hello world
docker run hello-world
#查看镜像
docker image ls
#查看容器
docker container ls
docker container ls --all
docker container ls -aq

#容器构建(friendlyhello)
docker build -t friendlyhello .
#容器启动
docker run -p 4000:80 friendlyhello
docker run -d -p 4000:80 friendlyhello
#查看停止容器
docker container ls
docker container ls -a
docker container stop 1fa4ab2cf395
docker container kill 1fa4ab2cf395
docker container rm 1fa4ab2cf395

#登陆login
docker login
#标记镜像
docker tag image username/repository:tag
#推送镜像
docker push username/repository:tag
#运行容器,没有就从仓库拉取
docker run -p 4000:80 username/repository:tag

#下载
curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#添加权限
chmod +x /usr/local/bin/docker-compose
#创建软连接
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
#测试是否安装成功
docker-compose --version

#运行你的负载均衡应用
#初始化swarm集群
docker swarm init
#基于docker-compose创建
docker stack deploy -c docker-compose.yml getstartedlab
#查看服务
docker service ls
#查看服务的任务
docker service ps getstartedlab_web
#查看容器
docker container ls -q
#修改docker-compose之后,扩展用用程序
docker stack deploy -c docker-compose.yml getstartedlab
#关闭应用用docker stack命令
docker stack rm getstartedlab
#关闭swarm
docker swarm leave --force

swarm简介

一个swarm由多个节点组成,节点可以是物理的活着虚拟的机器。

运行docker swarm init命令能够开启swarm模式,并且使你当前的机器成为swarm manager,运行docker swarm join命令可以让其他机器加入到swarm中成为worker机器。

#创建集群
docker-machine create --driver virtualbox myvm1
docker-machine create --driver virtualbox myvm2
#查看vm列表并获取他们的ip地址
docker-machine ls
#初始化swarm并添加节点
docker-machine ssh myvm1 "docker swarm init --advertise-addr <myvm1 ip>"
docker-machine ssh myvm2 "docker swarm join \
--token <token> \
<ip>:2377"

#查看swarm节点
docker-machine ssh myvm1 "docker node ls"

#总结
docker-machine create --driver virtualbox myvm1 # Create a VM (Mac, Win7, Linux)
docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm1 # Win10
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
docker-machine ssh myvm1 "docker swarm join-token -q worker"   # View join token
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)
docker-machine ssh myvm2 "docker swarm leave"  # Make the worker leave the swarm
docker-machine ssh myvm1 "docker swarm leave -f" # Make master leave, kill swarm
docker-machine ls # list VMs, asterisk shows which VM this shell is talking to
docker-machine start myvm1            # Start a VM that is currently not running
docker-machine env myvm1      # show environment variables and command for myvm1
eval $(docker-machine env myvm1)         # Mac command to connect shell to myvm1
& "C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe" env myvm1 | Invoke-Expression   # Windows 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-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-machine ssh myvm1 "docker stack deploy -c <file> <app>"   # Deploy an app using ssh (you must have first copied the Compose file to myvm1)
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
上一篇:machine-learning articles


下一篇:CentOS 8 使用 netatalk 实现 time machine