暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Docker 开始

技术白小白 2019-11-22
307

Docker

什么是Docker

Docker是linux容器的一种封装,提供简单易用的容器使用接口,在容器中打包和运行应用的功能。
Docker的隔离和安全性可以在主机上同时运行多个容器,不用担心环境问题。

Docker三个重要概念

  • Docker image:容器(container)依赖于image运行,镜像是只读的,一个镜像可以运行多个容器,镜像包含了每个容器私有的系统文件,使其与主机和其他容器隔离。

    镜像可以通过Dockerfile创建,也可以从Docker hub/registry上下载。

  • Docker container:容器运行在linux本地,并且与其他容器共享主机内核,容器是一个隔离环境,多个容器之间不会相互影响,保证容器中的程序运行在一个相对安全的环境中。

Get Docker

install Docker

yum install docker -y
复制

启动Docker服务

systemctl start docker.service
systemctl enable docker.service

复制

验证Docker是否安装成功

docker version
复制

命令行返回版本相关信息,表示安装成功。

修改Docker配置文件 daemon.json

  • 配置使用Docker加速器(连接 Docker 的官方仓库很慢)

    vim /etc/docker/daemon.json

{
"registry-mirrors": ["https://registry.docker-cn.com"],
"live-restore": true
}

复制
  • 为Docker指定DNS服务器

    vim /etc/docker/daemon.json

# 如果存在文件,则只添加该dns行
{
"dns": ["8.8.8.8", "8.8.4.4"]
}

复制

Hello World

在Docker上运行hello world镜像

  1. 将image从仓库拉取到本地

     docker pull hello-world

    复制
  2. 查看images

     docker images

    # 结果如下
    REPOSITORY TAG IMAGE ID CREATED SIZE
    docker.io/hello-world latest fce289e99eb9 10 months ago 1.84 kB

    复制
  3. 运行hello world image文件

     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.

    复制

    输出这段提示之后,hello world容器自动停止。

Docker命令

  • Docker命令大全(https://www.runoob.com/docker/docker-command-manual.html)

参考资料

  • Get Docker Engine - Community for CentOS(https://docs.docker.com/install/linux/docker-ce/centos/)

  • Orientation and setup(https://docs.docker.com/get-started/)


文章转载自技术白小白,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论