容器映射的端口异常

在防火墙,安全组都开放的情况,依然无法访问容器映射的端口

  1. 排查出docker启动后修改防火墙等规则,无法生效, 重启docker服务后问题解决.
  2. systemctl daemon-reload&&systemctl restart docker

    容器运行一段时间后莫名停止

    1. #!/bin/bash
    2. for proc in $(find /proc -maxdepth 1 -regex '/proc/[0-9]+'); do
    3. printf "%2d %5d %s\n"
    4. "$(cat $proc/oom_score)"
    5. "$(basename $proc)"
    6. "$(cat $proc/cmdline | tr '\0' ' ' | head -c 50)"
    7. done 2>/dev/null | sort -nr | head -n 40
    a. 该脚本执行完得到输出最高的40个进程, 内存不足时得分最高的会被直接杀死
    b. 配置swap 可以缓解
    适当调整容器的可用内存, 和容器内应用的内存大小

    docker镜像没有ifconfig、ping指令

    os: Ubuntu / debian
    apt-get update #更新源
    apt install net-tools # ifconfig
    apt install iputils-ping # ping
    apt install vim # vim

    容器访问宿主机 localhost

  1. 一般安装docker后 会出现一个 docker0 网卡,可以在容器中访问并指向主机 通常是 172.17.0.1 我的mysql容器中是 172.18.0.1
    而在容器中可以通过 ifconfig 查看 etho 找到 一个 _._.*.2 的ip 宿主机通过这个ip 可以访问宿主机

    时区问题

  2. 复制 /usr/share/zoneinfo/Asia/Shanghai 替换后容器中的 /etc/localtime

  3. 或者启动时 指定 env

    1. TZ=Asia/Shanghai

      docker清理硬盘空间

  4. docker system df

  5. docker system prune -a
  6. 在 /var/lib/docker/ 下 找到占用空间的 -json.log
    a. truncate -s 0
    -json.log 清空日志文件
    b. docker-compose 指定日志上限
    logging:
    driver:’json-file’
    options:
    max-size:’1g’

    docker运行spring boot 包镜像出现no main manifest attribute问题

    <build>
         <finalName>app</finalName>
         <plugins>
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <!--docker运行spring boot 包镜像出现no main manifest attribute问题-->
                 <!--项目基于maven pom多模块的开发的,需要设置goal-repackage属性为true,否则打包后文件依赖文件没有一起打包,然后镜像内没有可以运行的程序文件 需要加入下面两项配置-->
                 <executions>
                     <execution>
                         <goals>
                             <goal>repackage</goal>
                         </goals>
                     </execution>
                 </executions>
                 <configuration>
                     <includeSystemScope>true</includeSystemScope>
                 </configuration>
             </plugin>
         </plugins>
     </build>
    

docker 中无法执行 jinfo 等命令

cap_add:
- SYS_PTRACE