安装docker

apt install docker.io

安装docker-compose

apt install docker-compose

安装docker-machine

Docker Machine 是 Docker 官方提供的一个工具,它可以帮助我们在远程的机器上安装 Docker,或者在虚拟机 host 上直接安装虚拟机并在虚拟机中安装 Docker。我们还可以通过 docker-machine 命令来管理这些虚拟机和 Docker。下面是来自 Docker Machine 官方文档的一张图,很形象哦!
image

# 下载执行文件
root@ubuntu:~# wget https://github.com/docker/machine/releases/download/v0.13.0/docker-machine-Linux-x86_64

# 为该文件赋权
root@ubuntu:~# chmod +x docker-machine-Linux-x86_64

# 复制文件到系统Path
root@ubuntu:~# cp docker-machine-Linux-x86_64 /usr/local/bin/docker-machine

# 测试
root@ubuntu:~# docker-machine -v
docker-machine version 0.13.0, build 9ba6da9

初始化swarm

  1. 创建管理节点,在192.168.0.40上执行
root@manager:/home/app# docker swarm init
Swarm initialized: current node (u417bbra7ak5h6m57udf0mcdx) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-600m0y15u7zkuu23kam4j9pcyt9h15nqk9o57vn4i9d6hlqp8n-8oqtmhhns1vzg077y3b3djyed 192.168.0.40:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
  1. 添加工作节点,在192.168.0.41上执行
root@worker:~# docker swarm join --token SWMTKN-1-600m0y15u7zkuu23kam4j9pcyt9h15nqk9o57vn4i9d6hlqp8n-8oqtmhhns1vzg077y3b3djyed 192.168.0.40:2377
This node joined a swarm as a worker.

docker开启远程访问

# 查看系统运行docker状态
root@ubuntu:~# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e
   Active: active (running) since Thu 2019-01-31 22:33:16 CST; 11h ago
     Docs: https://docs.docker.com
 Main PID: 42867 (dockerd)
    Tasks: 19
   Memory: 73.5M
      CPU: 2min 37.763s
   CGroup: /system.slice/docker.service
           ├─42867 /usr/bin/dockerd -H fd://
           └─42876 docker-containerd --config /var/run/docker/containerd/contain

Warning: Journal has been rotated since unit was started. Log output is incomple

# 修改/lib/systemd/system/docker.service 文件
root@ubuntu:~# vi /lib/systemd/system/docker.service

# ExecStart=/usr/bin/dockerd -H fd:// 后面加上-H unix:///var/run/docker.dockk -H tcp://0.0.0.0:2375
ExecStart=/usr/bin/dockerd -H fd:// -H unix:///var/run/docker.dockk -H tcp://0.0.0.0:2375

# 重启docker
root@ubuntu:~# systemctl daemon-reload
root@ubuntu:~# service docker restart

Docker可视化工具portainer

$ docker volume create portainer_data
$ docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

Jenkins的volumes权限异常处理

# 查看容器内用户信息
root@manager:/home/docker/jenkins# docker run -ti --rm --entrypoint="/bin/bash" jenkins -c "whoami && id"
Unable to find image 'jenkins:latest' locally

latest: Pulling from library/jenkins
Digest: sha256:eeb4850eb65f2d92500e421b430ed1ec58a7ac909e91f518926e02473904f668
Status: Downloaded newer image for jenkins:latest
jenkins
jenkins
uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins)

# 为/home/docker/jenkins分配权限
root@manager:/home/docker# ls -la jenkins/
total 8
drwxr-xr-x 2 root root 4096 Jan 31 12:50 .
drwxr-xr-x 7 root root 4096 Jan 31 14:07 ..
root@manager:/home/docker# chown -R 1000 jenkins/

# 重启容器就可正常运行了

——————————————————————————
行路不知花开处,蓦然回首芷兰香。