Test your installation Docker

Linux > Test your installation Docker
23.03.2019 0:28:00

Наиболее часто встречающиеся слова в статье:

[container] [Pulling] [complete] [minutes] [webserver] [PowerShell] [running] [8aea0acb7423] [hello-world] [latest'']


Test your installation Docker

  1. Open a terminal window (Command Prompt or PowerShell, but not PowerShell ISE).

  2. Run docker --version to ensure that you have a supported version of Docker:

    > docker --version
    Docker version 18.03.0-ce, build 0520e24
  3. Pull the hello-world image from Docker Hub and run a container:

    > docker run hello-world
    docker : Unable to find image ''hello-world:latest'' locally
    Pulling from library/hello-world
    Pulling fs layer
    Download complete
    Pull complete
    Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
    Status: Downloaded newer image for hello-world:latest
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
  4. List the hello-world image that was downloaded from Docker Hub:

    > docker image ls
  5. List the hello-world container (that exited after displaying “Hello from Docker!”):

    > docker container ls --all
  6. Explore the Docker help pages by running some help commands:

    > docker --help
    > docker container --help
    > docker container ls --help
    > docker run --help

Explore the application

In this section, we demonstrate the ease and power of Dockerized applications by running something more complex, such as an OS and a webserver.

  1. Pull an image of the Ubuntu OS and run an interactive terminal inside the spawned container:

    > docker run --interactive --tty ubuntu bash
    docker : Unable to find image ''ubuntu:latest'' locally
    Pulling from library/ubuntu
    Pulling fs layer
    Pulling fs layer
    Pulling fs layer
    Digest: sha256:e348fbbea0e0a0e73ab0370de151e7800684445c509d46195aef73e090a49bd6
    Status: Downloaded newer image for ubuntu:latest

    Do not use PowerShell ISE

    Interactive terminals do not work in PowerShell ISE (but they do in PowerShell). See docker/for-win/issues/223.

  2. You are in the container. At the root # prompt, check the hostname of the container:

    root@8aea0acb7423:/# hostname

    Notice that the hostname is assigned as the container ID (and is also used in the prompt).

  3. Exit the shell with the exit command (which also stops the container):

    root@8aea0acb7423:/# exit
  4. List containers with the --all option (because no containers are running).

    The hello-world container (randomly named, relaxed_sammet) stopped after displaying its message. The ubuntu container (randomly named, laughing_kowalevski) stopped when you exited the container.

    > docker container ls --all
    CONTAINER ID    IMAGE          COMMAND     CREATED          STATUS                      PORTS    NAMES
    8aea0acb7423    ubuntu         "bash"      2 minutes ago    Exited (0) 2 minutes ago             laughing_kowalevski
    45f77eb48e78    hello-world    "/hello"    3 minutes ago    Exited (0) 3 minutes ago             relaxed_sammet
  5. Pull and run a Dockerized nginx web server that we name, webserver:

    > docker run --detach --publish 80:80 --name webserver nginx
    Unable to find image ''nginx:latest'' locally
    latest: Pulling from library/nginx
    fdd5d7827f33: Pull complete
    a3ed95caeb02: Pull complete
    716f7a5f3082: Pull complete
    7b10f03a0309: Pull complete
    Digest: sha256:f6a001272d5d324c4c9f3f183e1b69e9e0ff12debeb7a092730d638c33e0de3e
    Status: Downloaded newer image for nginx:latest
  6. Point your web browser at http://localhost to display the nginx start page. (You don’t need to append :80 because you specified the default HTTP port in the docker command.)

    Run nginx edge

  7. List only your running containers:

    > docker container ls
    CONTAINER ID    IMAGE    COMMAND                   CREATED          STATUS          PORTS                 NAMES
    0e788d8e4dfd    nginx    "nginx -g ''daemon of…"    2 minutes ago    Up 2 minutes>80/tcp    webserver
  8. Stop the running nginx container by the name we assigned it, webserver:

    >  docker container stop webserver
  9. Remove all three containers by their names -- the latter two names will differ for you:

    > docker container rm webserver laughing_kowalevski relaxed_sammet