• devops-1-docker安装


    @TOC源码安装docker

    yum安装 查看信息

    curl -o /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    yum mache
    cat /etc/redhat-release
    Linux Server release 7.2 (Paladin)
    uname -a
    Linux  4.9.151-015.3000.7.x86_64 #1 SMP Tue Mar 12 19:10:26 CST 2019 x86_64 x86_64 x86_64 GNU/Linux
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    源码安装

    下载路径

    wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.8.tgz
    tar zxvf docker-20.10.8.tgz
    cp docker/* /usr/bin/
     vi /etc/systemd/system/docker.service
    
    • 1
    • 2
    • 3
    • 4

    添加内容

    [Unit]
    
    Description=Docker Application Container Engine
    
    Documentation=https://docs.docker.com
    
    After=network-online.target firewall.service
    
    Wants=network-online.target
    
    [Service]
    
    Type=notify
    
    #the default is not to use systemd for cgroups because the delegay 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 process 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61

    配置服务

    chmod +x /etc/systemd/system/docker.service
    
    systemctl daemon-reload   #重新加载配置(每次修改文件后需执行)
    
    systemctl start docker.service
    
    systemctl status docker.service
    
    systemctl enable docker.service     ##使服务开启自启
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    vi /etc/docker/daemon.json

    {
        "registry-mirrors": ["https://registry.docker-cn.com","https://registry.docker-cn.com"]
    }
    
    • 1
    • 2
    • 3
    service docker restart
    docker info
    
    • 1
    • 2

    如果想修改docker镜像路径

    du -sh /var/lib/docker/
    320K	/var/lib/docker/
    
    service docker stop
    mkdir -p  var/lib/docker
    ln -s /home/xxxx/tmp/docker/var/lib/docker /var/lib/docker
    service docker start
    ls -ltr | grep docker
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    拉取镜像

    docker run -d -p 6379:6379 --name redis redis:latest
    #du -sh /var/lib/docker/
    #240M	/var/lib/docker/
    docker ps
    CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS              PORTS                    NAMES
    f0e742b9be40   redis:latest   "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:6379->6379/tcp   redis
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    brew not git repository

    haogeoyes@B-V1WTQ05P-0318 ~ % brew install git
    fatal: not in a git directory
    Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-cask, skipping update!
    fatal: not in a git directory
    Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-core, skipping update!
    fatal: not in a git directory
    Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
    ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/gettext-0.21.arm64_monterey.bottle.tar.gz
    Already downloaded: /Users/haogeoyes/Library/Caches/Homebrew/downloads/1de12628f1e5811fc7f479121352d4b4ef79b0747ca029098eb01dab21b5152e--gettext-0.21.arm64_monterey.bottle.tar.gz
    ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/pcre2-10.40.arm64_monterey.bottle.tar.gz
    Already downloaded: /Users/haogeoyes/Library/Caches/Homebrew/downloads/1e1f0fb3ee388c2b582280953cd239d1d312b159c8f2ddf91d947d8928f7f6e6--pcre2-10.40.arm64_monterey.bottle.tar.gz
    ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/git-2.37.1.arm64_monterey.bottle.tar.gz
    Already downloaded: /Users/haogeoyes/Library/Caches/Homebrew/downloads/aa30898350ce97da434638ba666a3b2b293f7db316ba17e092632a049bda3abe--git-2.37.1.arm64_monterey.bottle.tar.gz
    ==> Installing dependencies for git: gettext and pcre2
    ==> Installing git dependency: gettext
    fatal: not in a git directory
    Error: Command failed with exit 128: git
    
    此原因是因为brew 配置问题
    haogeoyes@B-V1WTQ05P-0318 ~ % brew -v
    Homebrew 3.5.7-11-g8a153de
    fatal: unsafe repository ('/opt/homebrew/Library/Taps/homebrew/homebrew-core' is owned by someone else)
    To add an exception for this directory, call:
    
    	git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
    Homebrew/homebrew-core (no Git repository)
    fatal: unsafe repository ('/opt/homebrew/Library/Taps/homebrew/homebrew-cask' is owned by someone else)
    To add an exception for this directory, call:
    
    	git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
    Homebrew/homebrew-cask (no Git repository)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    解决此问题先创建目录

    haogeoyes@B-V1WTQ05P-0318 ~ % mkdir /opt/homebrew/Library/Taps/homebrew/homebrew-cor
    haogeoyes@B-V1WTQ05P-0318 ~ % mkdir /opt/homebrew/Library/Taps/homebrew/homebrew-cask
    mkdir: /opt/homebrew/Library/Taps/homebrew/homebrew-cask: File exists
    haogeoyes@B-V1WTQ05P-0318 ~ % git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
    haogeoyes@B-V1WTQ05P-0318 ~ % git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
    
    • 1
    • 2
    • 3
    • 4
    • 5

    docker

    docker ps
    docker images
    docker search golang
    docker pull golang
    docker pull redis
    docker rmi -f golang
    Untagged: golang:latest
    Untagged: golang@sha256:c72fa9afc50b3303e8044cf28fb358b48032a548e1825819420fd40155a131cb
    Deleted: sha256:276895edf9673267f47528e8a99401f2d2947f6c9c00490f773d5ed8f559bef2
    
    docker ps
    CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS      NAMES
    bceb2d3927de   3e42dd4e79c7   "docker-entrypoint.s…"   59 minutes ago   Up 59 minutes   6379/tcp   nifty_black
    
    docker stop bceb2d3927de
    #导出
    docker save redis  -o redis.tar
    #加载
    docker load -i redis.tar
    Loaded image: redis:latest
    
    docker images
    REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
    redis        latest    3e42dd4e79c7   3 days ago   117MB
    #镜像tag
    docker tag redis:latest redis:pro
    docker images
    REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
    redis        latest    3e42dd4e79c7   3 days ago   117MB
    redis        pro       3e42dd4e79c7   3 days ago   117MB
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    # -it 表示 与容器进行交互式启动 -d 表示可后台运行容器 (守护式运行)  --name 给要运行的容器 起的名字  /bin/bash  交互路径
    docker run -it -d --name 要取的别名 镜像名:Tag /bin/bash
    docker run -it -d --name redis_docker redis:pro /bin/bash
    docker ps
    CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS      NAMES
    7246c5799195   redis:pro   "docker-entrypoint.s…"   10 minutes ago   Up 10 minutes   6379/tcp   redis_docker
    docker rename 容器ID/容器名 新容器名
    docker exec -it 容器名/容器ID /bin/bash
    docker attach 容器名/容器ID
    #-----直接退出  未添加 -d(持久化运行容器) 时 执行此参数 容器会被关闭  
    exit
    # 优雅提出 --- 无论是否添加-d 参数 执行此命令容器都不会被关闭
    Ctrl + p + q
    docker stop 容器ID/容器名
    docker restart 容器ID/容器名
    docker start 容器ID/容器名
    docker kill 容器ID/容器名
    
    #从容器内 拷出
    docker cp 容器ID/名称: 容器内路径  容器外路径
    #从外部 拷贝文件到容器内
    docker  cp 容器外路径 容器ID/名称: 容器内路径
    docker logs -f --tail=要查看末尾多少行 默认all 容器ID
    docker run -d -p 6379:6379 --name redis --restart=always  -v /var/lib/redis/data/:/data -v /var/lib/redis/conf/:/usr/local/etc/redis/redis.conf  redis:5.0.5 --requirepass "password"
    
    虚拟机创建镜像
    docker commit -m="提交信息" -a="作者信息" 容器名/容器ID 提交后的镜像名:Tag
    docker commit eafd9111ada6 docker/lua
    
    #  删除异常停止的容器
    docker rm `docker ps -a | grep Exited | awk '{print $1}'` 
     
    #  删除名称或标签为none的镜像
    docker rmi -f  `docker images | grep '' | awk '{print $3}'`
    查找大文件
    find / -type f -size +100M -print0 | xargs -0 du -h | sort -nr
    查找制定大小we年
    find / -type f -size +100M -print0 | xargs -0 du -h | sort -nr |grep '/var/lib/docker/overlay2/*'
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    完全清理镜像

    docker rmi -f imagename
    cd /var/lib/docker 
    rm -fr *
    
    • 1
    • 2
    • 3

    可用镜像

    docker ps -a
    docker search centos
    docker pull search
    # docker run -it -d --name test centos /bin/bash
    
    docker attach 44fc0f0582d9  
    docker exec -it 23 /bin/bash
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    docker -itd centos
    docker run -di -v /var/lib/docker:/mnt -p 6666:6666 centos
    docker exec -it 1c63a9800e7c /bin/bash
    
    • 1
    • 2
    • 3

    下载镜像

    docker pull centos:centos7
    wget -O ./CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
    
    docker build -t gozero:v1 .
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    Dockerfile

    gozero安装

    FROM centos:centos7
    RUN yum -y install wget
    RUN wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    RUN wget  -O /etc/yum.repos.d/go-repo.repo https://mirror.go-repo.io/centos/go-repo.repo
    # RUN yum clean all
    # RUN yum makecache
    RUN yum -y install go
    RUN mkdir -p  /root/go/bin
    RUN go env -w GO111MODULE=on
    RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
    RUN go install github.com/zeromicro/go-zero/tools/goctl@latest
    https://gitee.com/kevwan/go-zero/tree/master/tools/goctl
    
    vi ~/.bash_profile
    export PATH=$PATH:/Users/chenhaohao/go/bin
    source ~/.bash_profile
    wget https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-osx-x86_64.zip
    yum -y install unzip
    unzip protoc-21.4-osx-x86_64.zip
    mv bin/protoc ../go/bin/
    go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
    wget https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-osx-x86_64.zip
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    docker build -t gozero:v1 .

    虚拟机备份镜像
    docker commit 85e12a9736b7 gozero:latest
    启动虚拟机
    docker run -itd -v /var/lib/docker:/data -p 6666:6666 gozero

  • 相关阅读:
    [附源码]Python计算机毕业设计Django儿童早教课程管理系统论文2022
    剑指offer--Day6
    React如何进行条件渲染
    javaWeb项目中:连接mysql的驱动问题
    Visual Studio Code 快捷键大全
    每日刷题打卡Day18
    文献学习-6-微创手术中视频检索的无监督特征解缠
    vue原理相关
    四嗪活性基团修饰PROTACTetrazine-Ph-PEG5-Ph-tetrazine/acid/NHS ester/SS-amine性质研究
    (附源码)ssm在线学习网站 毕业设计 011451
  • 原文地址:https://blog.csdn.net/haogeoyes/article/details/126180933