美文网首页
docker在centos7下的安装和配置

docker在centos7下的安装和配置

作者: 琢石成器 | 来源:发表于2020-04-16 18:12 被阅读0次

1.docker说明:

1. 官网 https://www.docker.com/
2. 三要素: 镜像、仓库、容器
3. 特点: 一次封装,到处运行

2. docker安装:

centos7安装参考官方文档: <https://docs.docker.com/install/linux/docker-ce/centos/>
1. 卸载旧版本(如果原来已经安装过,没安装不需要执行)
    $ sudo yum remove docker \
              docker-client \
              docker-client-latest \
              docker-common \
              docker-latest \
              docker-latest-logrotate \
              docker-logrotate \
              docker-engine
2.安装 yum-utils
            sudo yum install -y yum-utils \
                          device-mapper-persistent-data \
                                 lvm2
3. 安装 docker stable 库
    sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

             上面链接可换成[http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo]

可选操作(4,5,6)

    4.
        sudo yum-config-manager --enable docker-ce-nightly
        
    5.
        sudo yum-config-manager --enable docker-ce-test
    6.
        sudo yum-config-manager --disable docker-ce-nightly

更新yum
yum makecache fast

7. 安装docker-ce
      sudo yum install docker-ce docker-ce-cli containerd.io

8. 启动docker
        sudo systemctl start docker 

自此 docker 在centos7上的安装完成

配置阿里云镜像:

vim /etc/docker/daemon.json
输入:

{
"registry-mirrors": ["你的阿里云镜像地址"]
}

保存
执行下面命令

systemctl daemon-reload
systemctl restart docker

测试:

docker run hello-world
因为是第一次执行,本地没有该镜像,会输出下列内容:

        Unable to find image 'hello-world:latest' locally
        latest: Pulling from library/hello-world
        1b930d010525: Pull complete 
        Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
        Status: Downloaded newer image for hello-world:latest

        Hello from Docker!
        This message shows that your installation appears to be working correctly.

        To generate this message, Docker took the following steps:
         1. The Docker client contacted the Docker daemon.
         2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
            (amd64)
         3. The Docker daemon created a new container from that image which runs the
            executable that produces the output you are currently reading.
         4. The Docker daemon streamed that output to the Docker client, which sent it
            to your terminal.

        To try something more ambitious, you can run an Ubuntu container with:
         $ docker run -it ubuntu bash

        Share images, automate workflows, and more with a free Docker ID:
         https://hub.docker.com/

        For more examples and ideas, visit:
         https://docs.docker.com/get-started/

此后再执行: docker run hello-world 则会直接输出:

        Hello from Docker!
        This message shows that your installation appears to be working correctly.

        To generate this message, Docker took the following steps:
         1. The Docker client contacted the Docker daemon.
         2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
            (amd64)
         3. The Docker daemon created a new container from that image which runs the
            executable that produces the output you are currently reading.
         4. The Docker daemon streamed that output to the Docker client, which sent it
            to your terminal.

        To try something more ambitious, you can run an Ubuntu container with:
         $ docker run -it ubuntu bash

        Share images, automate workflows, and more with a free Docker ID:
         https://hub.docker.com/

        For more examples and ideas, visit:
         https://docs.docker.com/get-started/

自此,docker环境安装配置完成!

卸载docker:

1. sudo yum remove docker-ce
2. sudo rm -rf /var/lib/docker

相关文章

网友评论

      本文标题:docker在centos7下的安装和配置

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