• in_array 踩坑
如果写法 in_array('*',$arr);  这种写法是错误的, 如果 $arr=[0]; 该判断就为true了
正确写法 !empty(array_instract(["*"],$arr)); 通过判断交集是否为空来判断更准确, 避免数组中包含 0 时导致字符串in_array都为true的情况 

危险命令, 切勿在生产环境使用, 执行前需要反复核对当前执行命令所在的连接的服务器的ip地址且关闭和非实验环境的shell连接

停止所有容器
docker stop $(docker ps -a -q) 
删除所有容器
docker rm $(docker ps -a -q)
删除所有镜像
docker rmi `docker images -a -q`
docker rmi -f `docker images -a -q` #可以保证镜像ID相同时还能正确删除


删除指定包含指定名称的容器名
docker stop $(docker ps -a | grep houdunren | awk '{print $1}')
docker rm $(docker ps -a | grep houdunren | awk '{print $1}')
# 强制删除包含指定名称的镜像
docker rmi -f $(docker images -a | grep houdunren | awk '{print $3}')
  • docker images -a 但是, 最后还是有无法删除的镜像
[root@localhost ~]# docker images -a
REPOSITORY          TAG                   IMAGE ID            CREATED             SIZE
hyperf/hyperf       7.2-alpine-v3.9-cli   1a067b031e1a        2 months ago        80.2MB
hyperf/hyperf       latest                1a067b031e1a        2 months ago        80.2MB
  • docker rmi $(docker images -q)
[root@localhost ~]# docker rmi `docker images -q`
Error response from daemon: conflict: unable to delete 1a067b031e1a (must be forced) - image is referenced in multiple repositories
Error response from daemon: conflict: unable to delete 1a067b031e1a (must be forced) - image is referenced in multiple repositories
  • 改为 docker rmi -f docker images -q 后成功删除
[root@localhost ~]# docker rmi -f `docker images -q`
Untagged: hyperf/hyperf:7.2-alpine-v3.9-cli
Untagged: hyperf/hyperf:latest
Untagged: hyperf/hyperf@sha256:133662bcd066f1826d44a971d876d3ca65910f0fbc881212526a5ef1c08c2502
Deleted: sha256:1a067b031e1a08101f89dca4bdc0a9ec47fae5df21ae8eb3842fe621123d52d6
Deleted: sha256:b78f069ad4b5383f0b0e71ea207dfd5d0c7878ca90d82df3ed0dd189992c1a1c
Deleted: sha256:be154a0e98e8945dbe8f4576f4688a6a857931f6dcb66522dbc5dc92ee664ead
Deleted: sha256:89ae5c4ee501a09c879f5b58474003539ab3bb978a553af2a4a6a7de248b5740
Error: No such image: 1a067b031e1a
  • 核查确认, 问题成功解决
[root@localhost ~]# docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

  • 网络环境
192.168.56.1 为不可联网的局域网
192.168.2.1 为可联网的局域网

一般是路由问题, 路由优先级高的路由是不能联网的网段, 导致了无法联网

[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.56.1    0.0.0.0         UG    100    0        0 enp0s3
0.0.0.0         192.168.2.1     0.0.0.0         UG    101    0        0 enp0s8
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-bc50ad6b6c9b
172.21.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-bf445a7984dd
172.23.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-ed0e3c7e7e65
172.30.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-8c9e9e38a72d
192.168.2.0     0.0.0.0         255.255.255.0   U     101    0        0 enp0s8
192.168.32.0    0.0.0.0         255.255.240.0   U     0      0        0 br-f1aee05d16bb
192.168.56.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
192.168.144.0   0.0.0.0         255.255.240.0   U     0      0        0 br-696dcda373dd
192.168.160.0   0.0.0.0         255.255.240.0   U     0      0        0 br-22be33c502cc
[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    100    0        0 enp0s3
default         _gateway        0.0.0.0         UG    101    0        0 enp0s8
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-bc50ad6b6c9b
172.21.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-bf445a7984dd
172.23.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-ed0e3c7e7e65
172.30.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-8c9e9e38a72d
192.168.2.0     0.0.0.0         255.255.255.0   U     101    0        0 enp0s8
192.168.32.0    0.0.0.0         255.255.240.0   U     0      0        0 br-f1aee05d16bb
192.168.56.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
192.168.144.0   0.0.0.0         255.255.240.0   U     0      0        0 br-696dcda373dd
192.168.160.0   0.0.0.0         255.255.240.0   U     0      0        0 br-22be33c502cc
  • 删除命令
[root@localhost ~]# route del -net default netmask 0.0.0.0 metric 100

参考内容, 命令输错了, 给了提示, 参考提示写的
[root@localhost ~]# route del -net default netmask 0.0.0.0 MASK enp0s3
Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]
       inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]
                              [netmask N] [mss Mss] [window W] [irtt I]
                              [mod] [dyn] [reinstate] [[dev] If]
       inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject
       inet_route [-FC] flush      NOT supported
  • 再次ping www.baidu.com
一切正常了, 但是重启后这条路由依旧存在, 查询了文档得知这种修改只是临时性的, 需要修改对应的网卡配置文件才行
  • [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=no # 原来这一行为yes, 我改为no后, 重启后那条路由不见了, ping百度也正常了
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=7e7e1163-222c-4630-8478-b0708e85ac2d
DEVICE=enp0s3
ONBOOT=yes

IPADDR=192.168.56.7
NETMASK=255.255.255.0
GATEWAY=192.168.56.1
#DNS1=192.168.56.1
  • route -n
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.2.1     0.0.0.0         UG    101    0        0 enp0s8
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-bc50ad6b6c9b
172.21.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-bf445a7984dd
172.23.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-ed0e3c7e7e65
172.30.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-8c9e9e38a72d
192.168.2.0     0.0.0.0         255.255.255.0   U     101    0        0 enp0s8
192.168.32.0    0.0.0.0         255.255.240.0   U     0      0        0 br-f1aee05d16bb
192.168.56.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
192.168.144.0   0.0.0.0         255.255.240.0   U     0      0        0 br-696dcda373dd
192.168.160.0   0.0.0.0         255.255.240.0   U     0      0        0 br-22be33c502cc

  • Dockerfile
# Default Dockerfile
#
# @link     https://www.hyperf.io
# @document https://doc.hyperf.io
# @contact  group@hyperf.io
# @license  https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE

FROM hyperf/hyperf:latest

##
# ---------- env settings ----------
##
# --build-arg timezone=Asia/Shanghai
ARG timezone

ENV TIMEZONE=${timezone:-"Asia/Shanghai"}
#    COMPOSER_VERSION=1.9.1 \
#    APP_ENV=prod \
#    SCAN_CACHEABLE=(true)

# update
RUN set -ex \
#    && apk update \
    # install composer
    # && cd /tmp \
    # && wget https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar \
    # && wget http://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar \
    # && chmod u+x composer.phar \
    # && mv composer.phar /usr/local/bin/composer \
    # show php version and extensions
    && php -v \
    && php -m \
    && php --ri swoole \
    && echo -e "\033[42;37m Build Completed :).\033[0m\n"


# Composer Cache
# COPY ./composer.* /opt/www/
# RUN composer install --no-dev --no-scripts

# RUN composer install --no-dev -o && php bin/hyperf.php
# COPY . /opt/www

WORKDIR /var/www/html
# RUN php /var/www/html/bin/hyperf.php
EXPOSE 9501
# ENTRYPOINT ["php", "/var/www/html/bin/hyperf.php", "start"]
# ENTRYPOINT ["sh"]
  • docker-compose.yml
version: "3"
services:
  hyperf:
    build:
      context: ./
      dockerfile: ./Dockerfile
    ports:
      - "9501:9501"
    command: ["php", "/var/www/html/bin/hyperf.php", "start"]
    volumes:
      - .:/var/www/html
    restart: always
  • 在代码目录中执行即可
docker-compose down && docker-compose up -d

数据表前置条件

  • project_users
uidtag_ids
100001002(NULL)
1(NULL)
100001006(NULL)
100001011["2", "4", "11"]
100001012["2", "4", "7", "11"]
100001013["4", "5", "11", "24", "17", "19"]
100001014["2", "4", "11"]
100001015["4", "9", "11", "10"]
100001016["4", "11", "17"]
100001017["2", "4", "5", "7", "11"]
  • user_tag_types
idnamememo
1合作商
2代理商
3老用户
4奇迹30学员
5灵性之美
6三千面相

  • 编写sql
SELECT xx.uid,tag_ids,GROUP_CONCAT(tag_title) AS 'user_tag_names' FROM 
(
SELECT uid,tag_ids,SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(REPLACE(REPLACE(REPLACE(t1.tag_ids,' ',''),'[',''),']',''),'"',''),',',t2.help_topic_id + 1),',',-1) AS tag_id
FROM user_center.`project_users` t1 JOIN mysql.help_topic t2
WHERE t2.help_topic_id< (LENGTH(t1.tag_ids) - LENGTH(REPLACE(t1.tag_ids,',','')) + 1)
) xx
INNER JOIN (SELECT id,IF(memo='',`name`,memo) AS tag_title FROM user_center.`user_tag_types` ) ut ON ut.id=xx.tag_id
GROUP BY xx.uid
  • 执行结果
uidtag_idsuser_tag_names
10000["9", "10"]工作室成员,免费特权
100001000["4", "11"]奇迹30学员,精品课
100001004["4"]奇迹30学员
100001011["2", "4", "11"]代理商,奇迹30学员,精品课
100001012["2", "4", "7", "11"]奇迹30学员,灵商密码,精品课,代理商
100001013["4", "5", "11", "24", "17", "19"]代理41,奇迹30学员,灵性之美,精品课,现场课到新代理商,代理21