美文网首页
测试 Docker 环境

测试 Docker 环境

作者: moralok | 来源:发表于2020-03-24 14:40 被阅读0次

    翻译自:开始 Docker

    设置你的 Docker 环境

    下载并安装 Docker 桌面版

    Docker Desktop is an easy-to-install application for your Mac or Windows environment that enables you to start coding and containerizing in minutes. Docker Desktop includes everything you need to build, run, and share containerized applications right from your machine.

    Docker 桌面版是一个适用于 Mac 和 Windows 环境且易于安装的应用。这使你可以在几分钟内开始编程和容器化。Docker 桌面版包含直接从你的机器中进行构建、运行和容器化所需要的一切。

    Follow the instructions appropriate for your operating system to download and install Docker Desktop:

    按照适用于您的操作系统的说明下载并安装Docker Desktop:

    测试 Docker 版本

    After you’ve successfully installed Docker Desktop, open a terminal and run docker --version to check the version of Docker installed on your machine.

    在你成功安装 Docker 桌面版后,打开终端并运行命令 docker --version 以检查在你的机器上安装的 Docker 版本。

    $ docker --version
    Docker version 19.03.4, build 9013bf583a
    

    测试 Docker 的安装

    Test that your installation works by running the hello-world Docker image:

    1. 通过运行 hello-world Docker 镜像来测试你的安装是可以有效工作的:

    如果你的机器上没有 hello-world 镜像,docker 会自动下载。

    $ docker run hello-world
    
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    ca4f61b1923c: Pull complete
    Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    ...
    

    如果已经下载过镜像,则无需重新下载。

    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 大致的处理步骤。

    1. Docker 客户端连接 Docker 守护进程。
    2. Docker 守护进程从 Docker 仓库拉取 hello-world 镜像。
    3. Docker 守护进程根据该镜像创建一个新容器,容器运行可执行文件生成你当前正在读取的输出。
    4. Docker 守护进程将输出流式传输到 Docker 客户端,客户端再输出到终端。

    Run docker image ls to list the hello-world image that you downloaded to your machine.

    1. 运行 docker image ls 列出你下载到机器上的 hello-world 镜像。REPOSITORY 为 ubuntu、openjdk 的镜像是下载到机器中的其他镜像,可以忽略。
    $ docker image ls
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    docker-demo         1.1                 59a905ff2dbe        4 months ago        125MB
    ubuntu              latest              cf0f3ca922e0        5 months ago        64.2MB
    openjdk             8-jdk-alpine        a3562aa0b991        10 months ago       105MB
    hello-world         latest              fce289e99eb9        14 months ago       1.84kB
    

    List the hello-world container (spawned by the image) which exits after displaying its message. If it is still running, you do not need the --all option:

    1. 使用命令 docker container ls 列出 hello-world 容器,该容器是由对应的 hello-world 镜像生成,并在展示完它的信息后退出。如果一个容器仍然处于运行中,你不需要添加 --all 选项

    展示了已经停止运行的容器:

    $ docker container ls --all
    
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                         PORTS               NAMES
    63682d5e681a        hello-world         "/hello"            About an hour ago   Exited (0) About an hour ago                       objective_almeida
    

    展示了正在运行的容器:

    $ docker container ls
    
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
    8f79ccd071e5        59a905ff2dbe        "java -Djava.securit…"   4 months ago        Up 4 months         0.0.0.0:8990->8990/tcp   docker-server
    

    结论

    At this point, you’ve installed Docker Desktop on your development machine, and ran a quick test to ensure you are set up to build and run your first containerized application.

    至此,你已经在开发机器上安装了 Docker 桌面版,并进行了快速测试,以确保你已设置好去构建并运行第一个容器化应用程序。

    相关文章

      网友评论

          本文标题:测试 Docker 环境

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