标签归档:docker

docker 无法启动 mysql 容器可能的解决办法

启动 mysql:8.* 效果很好,但 mysql:5.7.* 会导致立即 100% 内存消耗,尝试通过以下方法解决。

方法1

  1. 编辑 /lib/systemd/system/containerd.service ,修改 LimitNOFILE=infinityLimitNOFILE=1048576
  2. sudo systemctl daemon-reload
  3. sudo systemctl restart containerd.service

再尝试启动 mysql 容器。

方法2

  1. 编辑 /etc/docker/daemon.json
{
    // 原有配置...
    "default-ulimits": {
        "nofile": {
            "Name": "nofile",
            "Hard": 64000,
            "Soft": 64000
        }
    }
}

2. 重启服务 systemctl restart docker

参考:https://sukbeta.github.io/docker-ulimit-configure/

docker容器的重启策略

Use a restart policy

To configure the restart policy for a container, use the --restart flag when using the docker run command. The value of the --restart flag can be any of the following:

FlagDescription
noDo not automatically restart the container. (the default)
on-failure[:max-retries]Restart the container if it exits due to an error, which manifests as a non-zero exit code. Optionally, limit the number of times the Docker daemon attempts to restart the container using the :max-retries option.
alwaysAlways restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted. (See the second bullet listed in restart policy details)
unless-stoppedSimilar to always, except that when the container is stopped (manually or otherwise), it is not restarted even after Docker daemon restarts.

参考:https://docs.docker.com/config/containers/start-containers-automatically/

docker 退出集群模式的办法

当收到如下警告:

WARNING: The Docker Engine you’re using is running in swarm mode.

如果确认不需要/没有使用集群模式,可以使用以下命令退出:

docker swarm leave --force

阿里ECS部署jar包发生无法解析计算机名的问题

在ECS上利用 docker 部署 jar 包时出现如下错误:

redis.clients.jedis.HostAndPort - cant resolve localhost address

是因为spring-redis在初始化时会实例化LocalHost,但是ECS的host name并没有在设置,解决方案是在 /etc/hosts 中设置ECS的host name。

比如:ssh 登录后,界面显示 user@abcdefg ,则在 /etc/hosts 中添加 127.0.0.1 abcdefg

docker 轻量级管理工具 portainer

1、准备好 docker 环境
2、拉取镜像:

docker pull portainer/portainer

3、运行实例:

# 单机(本机)
docker run -d --name portainer -p 9000:9000 -v "/var/run/docker.sock:/var/run/docker.sock" portainer/portainer

# 群集
docker run -d --name portainer -p 9000:9000 portainer/portainer

4、添加 docker registries

名称:microsoft
地址:dockerhub.azk8s.cn

docker 中安装 jenkins

安装 docker

安装 docker 并使用国内加速器

拉取 jenkins 镜像

docker pull jenkins/jenkins

运行 docker jenkins

docker run -p 8080:8080 -p 50000:50000 -v /home/jenkins_home:/var/jenkins_home jenkins/jenkins

jenkins 安装密钥

首次安装时要求输入安装密钥,需要首先进入 docker 容器内,再查看对应的文件。

docker exec -it jenkins bash

继续阅读