docker: 23 items found.

Docker 容器的健康检查

健康检查 (HEALTHCHECK) 指令简介

健康检查 (HEALTHCHECK) 指令告诉 Docker 如何检查容器是否仍在工作。 它能够监测类似一个服务器虽然服务进程仍在运行, 但是陷入了死循环, 不能响应新的请求的情况。

当一个容器有指定健康检查 (HEALTHCHECK) 时, 它除了普通状态之外, 还有健康状态 (health status) 。 健康状态的初始状态是正在启动 (starting) , 一旦通过了一个健康检查, 它将变成健康 (healthy) (不管之前的状态是什么), 经过一定数量的连续失败之后, 它将变成不健康 (unhealthy) 。

More ~

windows环境使用CentOS7虚拟机安装minikube

in10环境,安装的VMware Workstation Pro,创建了一台Centos7.x的虚拟机。并启用虚拟化。
截图20191015175316721.jpg

先安装kubectl

// v1.16.0版本可以从这里查 https://storage.googleapis.com/kubernetes-release/release/stable.txt
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version

上述如果在墙内,需要http代理可以,先将代理设为环境变量 export http_proxy=http://ip:port

也可以从github上下载
https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG.md#client-binaries-1
找到Current release如 https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.16.md
再找到Client Binaries如v1.16.0下的 https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.16.md#client-binaries
再找到合适的tar包如 https://dl.k8s.io/v1.16.0/kubernetes-client-linux-amd64.tar.gz

wget https://dl.k8s.io/v1.16.0/kubernetes-client-linux-amd64.tar.gz
tar -zxvf kubernetes-client-linux-amd64.tar.gz
cd kubernetes/client/bin
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version
More ~

docker images filter 镜像查询过滤

找出tag为<none>
docker images -f "dangling=true"

找出tag为<none>的, 只返回image id
docker images -f "dangling=true" -q

根据repository名称和tag模糊过滤,我验证时,如果repository有/或小数点符号,通过*是无法匹配的
docker images --filter=reference='busy*:*libc'

使用beforesince根据时间查找,实际上以repository的名字作为时间分隔,
docker images --filter "before=image1"

docker images --filter "since=image3"

此外还有label, label=<key> or label=<key>=<value>
docker images --filter "label=com.example.version" , 这条我用docker image inspect <image id>,发现几个image的label都是空的,这个有待研究。

More ~

很诡异的301跳转,记wordpress上线问题

话说本地用docker-compose搭了个wordpress的站点,设置里site url和home都是本地地址http://localhost:8300 ,然后上线的数据库数据是导出后导入进来。

用nginx反向代理wordpress的容器地址,浏览器卡住半天自动跳转到www.xxx.com:8300, 这很诡异啊,一直在怀疑是不是nginx配错了,proxy_redirect是off的。 即使重新安装nigix也无济无事。 curl -i 看看响应头确实301跳转了

Screen Shot 2019-07-22 at 01.15.02.png

More ~

docker untag? How to remove a tagged image which used docker tag

There is no docker untag command, so, the answer is find the repository which using the image and execute
docker rmi <REPOSITORY>:<TAG>

There are the commands we executed before to tag a new image with an image id

docker tag <image id> hkccr.ccs.tencentyun.com/xxx/fff:v0.1.4

And remove the tagged image
docker rmi hkccr.ccs.tencentyun.com/xxx/fff:v0.1.4

More ~

alpine based image to docker compose get error: command 'gcc' failed with exit status 1

Error like this:

Collecting misaka==2.1.1 (from -r requirements.txt (line 12))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fa/87/b1020510a00aba1b936477e54180b143df654c565b84936b0b3e85272cf2/misaka-2.1.1.tar.gz (125kB)
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: 
        No working compiler found, or bogus compiler options passed to
        the compiler from Python's standard "distutils" module.  See
        the error messages above.  Likely, the problem is not related
        to CFFI but generic to the setup.py of any Python package that
        tries to compile C code.  (Hints: on OS/X 10.8, for errors about
        -mno-fused-madd see http://stackoverflow.com/questions/22313407/
        Otherwise, see https://wiki.python.org/moin/CompLangPython or
        the IRC channel #python on irc.freenode.net.)
    
        Trying to continue anyway.  If you are trying to install CFFI from
        a build done in a different context, you can ignore this warning.
    
    Traceback (most recent call last):
      File "/usr/local/lib/python3.7/distutils/unixccompiler.py", line 118, in _compile
        extra_postargs)
      File "/usr/local/lib/python3.7/distutils/ccompiler.py", line 909, in spawn
        spawn(cmd, dry_run=self.dry_run)
      File "/usr/local/lib/python3.7/distutils/spawn.py", line 36, in spawn
        _spawn_posix(cmd, search_path, dry_run=dry_run)
      File "/usr/local/lib/python3.7/distutils/spawn.py", line 159, in _spawn_posix
        % (cmd, exit_status))
    distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1

And my Dockerfile is here:

More ~

Using mongodb service in docker-compose.yml

version: '3.1'

services:

  web:
    build: .
    restart: always
    ports:
      - 8080:80
    environment:      
      MONGODB_HOST: mongodb
      MONGODB_USER: root
      MONGODB_PWD: 123456
    depends_on:
      - mongodb

  mongodb:
    image: mongo:4.1
    restart: on-failure
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: 123456
    volumes:
      - ./data/mongo:/data/db
      - ./data/mongo-entrypoint/:/docker-entrypoint-initdb.d/

More ~

容器化之路 - 面对一堆yml配置我很茫然

对于容器的配置文件, docker-compose的还好理解,但是一到k8s,就有很多对象, pods, nodes, services, deployment... 每个基本上都有个yml的定义,其中的参数一看一脸茫然。

还好找到这个:kubectl explain xxx 可以看它的定义

kubectl explain service --recursive 可以查看service定义的所有定段。
kubectl explain svc.metadata.uid 可以查看某个字段的定义

当然,k8s官方也有一些examples: https://github.com/kubernetes/examples

More ~