• docker安装


    一、安装docker
    安装依赖环境
    yum -y install yum-utils device-mapper-persistent-data  lvm2
    1
    准备镜像源
     curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
    1
    安装docker
     yum -y install docker-ce
    1
    启动docker查看docker版本
     systemctl start docker
     
    docker version
    Client: Docker Engine - Community
     Version:           19.03.4
     API version:       1.40
     Go version:        go1.12.10
     Git commit:        9013bf583a
     Built:             Fri Oct 18 15:52:22 2019
     OS/Arch:           linux/amd64
     Experimental:      false
    Server: Docker Engine - Community
     Engine:
      Version:          19.03.4
      API version:      1.40 (minimum version 1.12)
      Go version:       go1.12.10
      Git commit:       9013bf583a
      Built:            Fri Oct 18 15:50:54 2019
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.2.10
      GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
     runc:
      Version:          1.0.0-rc8+dev
      GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
     docker-init:
      Version:          0.18.0
      GitCommit:        fec3683
    #查看docker信息
    docker info
    12345678910111213141516171819202122232425262728293031323334
    阿里云加速器
    阿里云加速器网址
    sudo tee /etc/docker/daemon.json <<-'EOF'
    {
      "registry-mirrors": ["https://rxspsdcu.mirror.aliyuncs.com"]
    }
    EOF
    -----------------------------------------------------------------
    #重新加载配置,重启服务
    systemctl daemon-reload
    systemctl restart docker
    12345678910
    二、docker关于镜像的基本操作
    查找docker镜像
    docker search -s 100 nginx
    -s 100 星级评价高于100
    12
    下载镜像
    docker pull nginx
    注:如果不加标签默认下载latest,最新的镜像
    12
    查看下载的镜像
    docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED   SIZE
    nginx               latest              540a289bab6c        3 weeks ago   126MB
    tomcat              latest              882487b8be1d        3 weeks ago   507MB
    12345
    查看镜像信息
    docker inspect nginx  (镜像ID号)
    1
    更改镜像名或标签
    docker tag nginx:latest mynginx:wang
    [root@serverB ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED   SIZE
    mynginx             latest              540a289bab6c        3 weeks ago   126MB
    mynginx             wang                540a289bab6c        3 weeks ago   126MB
    nginx               latest              540a289bab6c        3 weeks ago   126MB
    tomcat              latest              882487b8be1d        3 weeks ago   507MB
    12345678
    删除镜像
    docker rmi mynginx:latest
    Untagged: mynginx:latest
    docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED   SIZE
    nginx               latest              540a289bab6c        3 weeks ago   126MB
    mynginx             wang                540a289bab6c        3 weeks ago   126MB
    tomcat              latest              882487b8be1d        3 weeks ago   507MB
    123456789
    保存镜像到本地
    docker save -o nginx.tar nginx:latest
    ls
    anaconda-ks.cfg  nginx.tar
    1234
    将本地文件导入镜像
     docker load < nginx.tar
    Loaded image: nginx:latest
    [root@serverB ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED   SIZE
    mynginx             wang                540a289bab6c        3 weeks ago   126MB
    nginx               latest              540a289bab6c        3 weeks ago   126MB
    tomcat              latest              882487b8be1d        3 weeks ago   507MB
    123456789
    将镜像上传到仓库
    docker push nginx:wang   #上传到默认仓库
    1
    三、docker关于容器的基本操作
    创建容器
    docker create -it nginx /bin/bash
    1
    查看容器
     docker ps -a   #查看全部容器
     CONTAINER ID        IMAGE               COMMAND             CREATED   STATUS              PORTS               NAMES
    cb69edb91977        nginx               "/bin/bash"         42 seconds ago   Created                                 jovial_zhukovsky
    docker ps #查看启动的容器
    12345
    创建并启动容器
    docker run -it -p 80:80 -v /html:/usr/share/nginx/html nginx /bin/bash
    root@f0d7e9b59fae:/# 
    退出容器
    exit :退出并关闭容器
    ctrl+p+q:快捷键 只是退出容器
    123456
    启动、关闭、重启容器
    docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED   STATUS              PORTS                NAMES
    f0d7e9b59fae        nginx               "/bin/bash"         3 minutes ago   Up 3 minutes        0.0.0.0:80->80/tcp   relaxed_panini
    cb69edb91977        nginx               "/bin/bash"         7 minutes ago   Created                                  jovial_zhukovsky
    #启动
    docker start cb69edb91977
    cb69edb91977
    [root@serverB ~]# docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED   STATUS              PORTS                NAMES
    f0d7e9b59fae        nginx               "/bin/bash"         3 minutes ago   Up 3 minutes        0.0.0.0:80->80/tcp   relaxed_panini
    cb69edb91977        nginx               "/bin/bash"         7 minutes ago   Up 1 second         80/tcp               jovial_zhukovsky
    #关闭
    [root@serverB ~]# docker stop cb69edb91977
    cb69edb91977
    [root@serverB ~]# docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED   STATUS                     PORTS                NAMES
    f0d7e9b59fae        nginx               "/bin/bash"         3 minutes ago   Up 3 minutes               0.0.0.0:80->80/tcp   relaxed_panini
    cb69edb91977        nginx               "/bin/bash"         7 minutes ago   Exited (0) 2 seconds ago                        jovial_zhukovsky
    #重启
    [root@serverB ~]# docker restart cb69edb91977
    cb69edb91977
     docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED   STATUS              PORTS                NAMES
    f0d7e9b59fae        nginx               "/bin/bash"         4 minutes ago   Up 4 minutes        0.0.0.0:80->80/tcp   relaxed_panini
    cb69edb91977        nginx               "/bin/bash"         8 minutes ago   Up 38 seconds       80/tcp               jovial_zhukovsky
    #杀死
    [root@serverB ~]# docker kill cb69edb91977
    cb69edb91977
    [root@serverB ~]# docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED   STATUS                       PORTS                NAMES
    f0d7e9b59fae        nginx               "/bin/bash"         4 minutes ago   Up 4 minutes                 0.0.0.0:80->80/tcp   relaxed_panini
    cb69edb91977        nginx               "/bin/bash"         8 minutes ago   Exited (137) 2 seconds ago
    1234567891011121314151617181920212223242526272829303132
    删除容器
     docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED   STATUS                       PORTS                NAMES
    f0d7e9b59fae        nginx               "/bin/bash"         9 minutes ago   Up 9 minutes                 0.0.0.0:80->80/tcp   relaxed_panini
    cb69edb91977        nginx               "/bin/bash"         13 minutes ago   Exited (137) 4 minutes ago                        jovial_zhukovsky
    #删除容器
    [root@serverB ~]# docker rm -f cb69edb91977
    cb69edb91977
    [root@serverB ~]# docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED   STATUS              PORTS                NAMES
    f0d7e9b59fae        nginx               "/bin/bash"         9 minutes ago   Up 9 minutes        0.0.0.0:80->80/tcp   relaxed_panini
    1234567891011
    查看容器内的输出
    docker logs f0d7e9b59fae(容器ID)
    12
    切入容器内部
    docker attach f0d7e9b59fae (容器ID)
    root@f0d7e9b59fae:/#
    docker exec -it 3bee55d8f5a3 /bin/bash
    root@3bee55d8f5a3:/usr/local/tomcat#
    12345
    导出容器
    docker export 3bee55d8f5a3 > tomcat:wang
    ls
    anaconda-ks.cfg  nginx.tar  tomcat:wang
    1234
    导入容器
    cat tomcat:wang | docker import - tomcat:wang
    sha256:02819d370c0ec8bfc8990e7abbe2796c597f8c29764f9d5ed9d91d33a549a9a5
     docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED   SIZE
    tomcat              wang                02819d370c0e        22 seconds ago   499MB
    mynginx             wang                540a289bab6c        3 weeks ago   126MB
    nginx               latest              540a289bab6c        3 weeks ago   126MB
    tomcat              latest              882487b8be1d        3 weeks ago   507MB
    12345678910
    将真机文件复制到docker容器中
    docker cp anaconda-ks.cfg  3bee55d8f5a3:/webapps
     docker exec -it 3bee55d8f5a3 /bin/bash
    root@3bee55d8f5a3:/usr/local/tomcat# cd
    root@3bee55d8f5a3:~# ls /webapps/
    anaconda-ks.cfg
    1234567
                                       
                   

  • 相关阅读:
    php根据数组的某个值倒序和升序
    php函数排序方法 和 判断变量类型
    安装composer
    app生成token值 jwt生成
    Verilog语法基础讲解之参数化设计
    Verilog HDL基础语法讲解之模块代码基本结构
    NIOS II CPU复位异常的原因及解决方案
    关于Quartus II 13.0对应开发NIOS II软件程序时报错Symbol 'NULL' could not be resolved问题的解决方法
    ALTFP_CONVERT IP使用与仿真
    altera soc体验之旅 FPGA与ARM的窃窃私语
  • 原文地址:https://www.cnblogs.com/L1-5551/p/12483119.html
Copyright © 2020-2023  润新知