美文网首页
docker安装部署问题

docker安装部署问题

作者: 莫问_68ff | 来源:发表于2020-04-21 11:57 被阅读0次

    离线安装docker

    一、基础环境

    1、下载docker:https://download.docker.com/linux/static/stable/x86_64/
    2、网络正常得情况下直接yum install docker-ce

    二、Docker安装

    1、将下载好的docker上传到服务器上
    2、解压

    tar -xvf docker-18.06.1-ce.tgz
    

    3、将解压出来的docker文件内容拷贝到 /usr/bin/ 目录下

    cp docker/* /usr/bin/
    

    4、将docker注册为service

    vim /etc/systemd/system/docker.service
    

    将下列配置加到docker.service中并保存:

    [Unit]
    
    Description=Docker Application Container Engine
    
    Documentation=https://docs.docker.com
    
    After=network-online.target firewalld.service
    
    Wants=network-online.target
    
    [Service]
    
    Type=notify
    
    # the default is not to use systemd for cgroups because the delegate issues still
    
    # exists and systemd currently does not support the cgroup feature set required
    
    # for containers run by docker
    
    ExecStart=/usr/bin/dockerd
    
    ExecReload=/bin/kill -s HUP $MAINPID
    
    # Having non-zero Limit*s causes performance problems due to accounting overhead
    
    # in the kernel. We recommend using cgroups to do container-local accounting.
    
    LimitNOFILE=infinity
    
    LimitNPROC=infinity
    
    LimitCORE=infinity
    
    # Uncomment TasksMax if your systemd version supports it.
    
    # Only systemd 226 and above support this version.
    
    #TasksMax=infinity
    
    TimeoutStartSec=0
    
    # set delegate yes so that systemd does not reset the cgroups of docker containers
    
    Delegate=yes
    
    # kill only the docker process, not all processes in the cgroup
    
    KillMode=process
    
    # restart the docker process if it exits prematurely
    
    Restart=on-failure
    
    StartLimitBurst=3
    
    StartLimitInterval=60s
    
     
    
    [Install]
    
    WantedBy=multi-user.target
    

    5、启动

    chmod +x /etc/systemd/system/docker.service  #添加文件权限并启动docker
    
    systemctl daemon-reload   #重载unit配置文件
    
    systemctl start docker    #启动Docker
    
    systemctl enable docker.service  #设置开机自启
    

    6、验证

    systemctl status docker   #查看Docker状态
    
    docker -v    #查看Docker版本
    

    docker load导入镜像报错:

    open /opt/docker/installation/docker/tmp/docker-import-429515006/docker-images/json: no such file or director
    

    原因:下载的tar包缺少一些json文件

    解决办法:

    cat mysql5.7.19.tar | docker import - mysql5.7.19
    

    docker images就可以看到已经成功导入了

    开通docker2375端口

    1、新建daemon,json文件

    vi /etc/docker/daemon.json
    

    2、保存配置

    {
    "log-driver":"json-file",
    "log-opts": {"max-size":"500m", "max-file":"1"},
    "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"]
    }
    

    3、重启docker守护进程

    # systemctl daemon-reload
    
    # systemctl restart docker
    

    docker日志迁移方案

    1、停止docker服务

    systemctl stop docker
    

    2、创建存放docker的日志文件
    分别在此路径/opt/docker

    mkdir images
    mkdir installation
    

    3、vi clean_docker_logs.sh

    #!/bin/sh 
    
    echo "======== start clean docker containers logs ========"  
    
    logs=$(find /var/lib/docker/containers/ -name *-json.log)  
    
    for log in $logs  
            do  
                    echo "clean logs : $log"  
                    cat /dev/null > $log  
            done  
    
    echo "======== end clean docker containers logs ========"
    

    4、将原docker下的文件拷贝到新创建的目录下

    cp -a /var/lib/docker /opt/docker/installation/docker
    

    5、移动文件

    mv -u /var/lib/docker /var/lib/docker.bak
    

    6、建立软连接

    ln -fs /opt/docker/installation/docker /var/lib/docker
    

    7、重启docker

    systemctl start docker.service
    

    相关文章

      网友评论

          本文标题:docker安装部署问题

          本文链接:https://www.haomeiwen.com/subject/ewocvhtx.html