18篇 docker related articles

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 ~

Dockerfile指定pip安装源

Dockerfile使用的python3.7作为基础镜像 FROM python:3.7,但是执行
RUN pip install --no-cache-dir -r requirements.txt
是默认走了这个源,https://files.pythonhosted.org/packages,编译用时太久。

无赖修改成国内源来加快编译速度:
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir -r requirements.txt

附国内其它源:
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

More ~

docker-compose 指定文件

完整的文档在这里https://docs.docker.com/compose/reference/overview/

这里有个坑,不注意看可能和我一样会碰到,

docker-compose -f xxx.yml up -d, 这里 -f必须前置,否则执行一堆提示

More ~