docker证书问题和docker虚拟机中安装docker-compose

问题缘由

本来是 docker 虚拟机运行着好好的,突然报错:

Unable to query docker version: Get https://192.168.99.100:2376/v1.15/version: x509: certificate has expired or is not yet valid

很显然可以看到certificate has expired字样,网上查了半天,docker-machine regenerate-certsdocker-machine provision命令都试过了,没有作用。还有人说重建虚拟机,想想应该一定是有作用,但是里面的东西都要重建,很麻烦。发现docker-machine ssh是正常的,那就干脆 ssh 到虚拟机里面去操作。

docker虚拟机里面没有docker-compose,那就装一个,倒也不麻烦。按照官方的指导,两个命令搞定

sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

接下来的麻烦

后来才意识到,docker虚拟机重启以后,就要重新安装docker-compose,它这个虚拟机是不保留状态的呀!这一长串的命令,就只好记到我的 commands.txt 里面去,每次用的时候去找出来复制粘贴(我把常用的命令什么的都记在这个文件中,加上 Sublime ,基本还是能很快找到想要用的命令)。

另外一个事,许多容器没设置成自动启动,虚拟机重启以后,需要一一去启动,也是一样,记下来,用的时候找出来复制粘贴。

docker-compose -f /Users/mike/Projects/docker/mysql/docker-compose.yml restart
docker-compose -f /Users/mike/Projects/docker/redis/docker-compose.yml restart
docker-compose -f /Users/mike/Projects/docker/www1/docker-compose.yml restart
docker-compose -f /Users/mike/Projects/docker/www2/docker-compose.yml restart
docker-compose -f /Users/mike/Projects/docker/myadmin/docker-compose.yml restart
docker-compose -f /Users/mike/Projects/docker/nginx/docker-compose.yml restart

解决复制粘贴命令的烦恼

最近开始用 flashops ,立马想到,这些命令都弄到 flashops 里面去。有个小问题,就是得把 docker 虚拟机的 ssh 证书找出来,直接上结果,在这里:

/Users/mike/.docker/machine/machines/default/id_rsa

先上一下 flashops 配置

servers:
  - title: Docker Machine Default
    ssh:
      host: 192.168.99.100
      user: docker
      keyfile: /Users/mike/.docker/machine/machines/default/id_rsa
    operations:
      - title: Install Docker-Compose
        commands:
          - 'sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose'
          - 'sudo chmod +x /usr/local/bin/docker-compose'
      - title: Start all container
        commands:
          - 'docker-compose -f /Users/mike/Projects/docker/mysql/docker-compose.yml restart'
          - 'docker-compose -f /Users/mike/Projects/docker/redis/docker-compose.yml restart'
          - 'docker-compose -f /Users/mike/Projects/docker/www1/docker-compose.yml restart'
          - 'docker-compose -f /Users/mike/Projects/docker/www2/docker-compose.yml restart'
          - 'docker-compose -f /Users/mike/Projects/docker/myadmin/docker-compose.yml restart'
          - 'docker-compose -f /Users/mike/Projects/docker/nginx/docker-compose.yml restart'
          - 'docker ps'

再看一下整个执行过程

$ flashops
Hi, flashops
No config file provided, using FLASHOPS_FILE. -h to see the help.
File: /Users/mike/ds.yaml
[f] Files
[r] Projects
[s] Servers
[t] Tasks
[c] Statements
[D] Donation
Please input your choice ("exit" for quit): s1
Connecting to Docker Machine Default ...... Work path: /home/docker
[0] Check connection
[1] Install Docker-Compose
[2] Start all container
[3] Docker PS
(Docker Machine Default)Choose a Operation: 1
sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0   1080      0 --:--:-- --:--:-- --:--:--  1078
100 11.2M  100 11.2M    0     0  1070k      0  0:00:10  0:00:10 --:--:-- 1329k

sudo chmod +x /usr/local/bin/docker-compose

(Docker Machine Default)Choose a Operation: 2
docker-compose -f /Users/mike/Projects/docker/mysql/docker-compose.yml restart
Restarting mysql_mysql_1 ... done

docker-compose -f /Users/mike/Projects/docker/redis/docker-compose.yml restart
Restarting redis_redis_1 ... done

docker-compose -f /Users/mike/Projects/docker/www1/docker-compose.yml restart
Restarting www1_www_1 ... done

docker-compose -f /Users/mike/Projects/docker/www2/docker-compose.yml restart
Restarting www2_www_1 ... done

docker-compose -f /Users/mike/Projects/docker/myadmin/docker-compose.yml restart
Restarting myadmin_myadmin_1 ... done

docker-compose -f /Users/mike/Projects/docker/nginx/docker-compose.yml restart
Restarting nginx_nginx_1 ... done

docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                  PORTS                        NAMES
576e3033a294        nginx_nginx           "nginx -g 'daemon of…"   2 months ago        Up Less than a second   0.0.0.0:80->80/tcp           nginx_nginx_1
78f5013aa9d0        myadmin_myadmin       "catalina.sh jpda run"   2 months ago        Up 5 seconds            0.0.0.0:10080->8080/tcp      myadmin_myadmin_1
f128d0e01bfd        www1_www              "sh -c 'node www.js …"   2 months ago        Up 8 seconds            0.0.0.0:6081->3000/tcp       www1_www_1
6e33edbfc3d2        www2_www              "sh -c 'node www.js …"   2 months ago        Up 6 seconds            0.0.0.0:6082->3000/tcp       www2_www_1
298ae06c915c        mysql_mysql           "/entrypoint.sh mysq…"   2 months ago        Up 9 seconds            0.0.0.0:3306->3306/tcp       mysql_mysql_1
6950e6bcf2e9        redis                 "/entrypoint.sh redi…"   2 months ago        Up 8 minutes            0.0.0.0:6379->6379/tcp       redis_redis_1

(Docker Machine Default)Choose a Operation: 

整个操作,只输入了

s1
1
2

比起到 commands.txt 里去找命令、复制粘贴舒服多了。

最后

再说一下 docker 虚拟机证书的问题,最后我还是重建了 docker 虚拟机(重建里面的容器什么的倒是容易的,就是导入数据库太慢,电脑不给力啊,足足等了一个多小时)。

你可能感兴趣的:(docker证书问题和docker虚拟机中安装docker-compose)