Windows之docker安装及简单使用

本文详细介绍了Docker的安装步骤,包括从官方网站下载安装包并进行配置。同时,深入探讨了Docker的启动过程及常见环境变量设置。此外,还提供了如何使用Docker命令行界面来拉取、运行和管理镜像的实例,如hello-world和python镜像的使用。通过本文,读者可以了解Docker的基本操作和解决一些常见的错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装

docker下载地址 :https://github.com/boot2docker/windows-installer/releases

一路next即可。

在这里插入图片描述

启动

点击boot2Docker start :

copying initial boot2docker.iso (run "boot2docker.exe download" to update)
initializing...

  WARNING: The 'boot2docker' command line interface (not to be confused with
  'boot2docker' the operating system) is officially deprecated.

  Please switch to Docker Machine (https://docs.docker.com/machine/) ASAP.

  Docker Toolbox (https://docker.com/toolbox) is the recommended install method.

Generating public/private rsa key pair.
Your identification has been saved in C:\Users\lenovo\.ssh\id_boot2docker.
Your public key has been saved in C:\Users\lenovo\.ssh\id_boot2docker.pub.
The key fingerprint is:
SHA256:w3r2gNIgLUZw5c8GT/1umF9w9GtD9PPYI2GpMTaV4VE lenovo@YXY-SZ-047
The key's randomart image is:
+---[RSA 2048]----+
|. ...        o.E |
| o .   .    . +  |
|  . o . .   .+.  |
| . . * . . ..o.. |
|  + o = S o=.+o..|
| . o + o =.o*..+o|
|    . + * o...=.o|
|     . o = . ....|
|          o      |
+----[SHA256]-----+
Initialization of virtual machine "boot2docker-vm" complete.
Use `boot2docker up` to start it.

starting...

  WARNING: The 'boot2docker' command line interface (not to be confused with
  'boot2docker' the operating system) is officially deprecated.

  Please switch to Docker Machine (https://docs.docker.com/machine/) ASAP.

  Docker Toolbox (https://docker.com/toolbox) is the recommended install method.

Waiting for VM and Docker daemon to start...
.......................oooooooooooo
Started.
Writing C:\Users\lenovo\.boot2docker\certs\boot2docker-vm\ca.pem
Writing C:\Users\lenovo\.boot2docker\certs\boot2docker-vm\cert.pem
Writing C:\Users\lenovo\.boot2docker\certs\boot2docker-vm\key.pem

To connect the Docker client to the Docker daemon, please set:
    export DOCKER_TLS_VERIFY=1
    export DOCKER_HOST=tcp://192.168.59.103:2376
    export DOCKER_CERT_PATH='C:\Users\lenovo\.boot2docker\certs\boot2docker-vm'

Or run: `eval "$(boot2docker shellinit)"`


IP address of docker VM:
192.168.59.103

setting environment variables ...
Writing C:\Users\lenovo\.boot2docker\certs\boot2docker-vm\ca.pem
Writing C:\Users\lenovo\.boot2docker\certs\boot2docker-vm\cert.pem
Writing C:\Users\lenovo\.boot2docker\certs\boot2docker-vm\key.pem
    export DOCKER_CERT_PATH='C:\\Users\\lenovo\\.boot2docker\\certs\\boot2docker-vm'
    export DOCKER_TLS_VERIFY=1
    export DOCKER_HOST=tcp://192.168.59.103:2376

You can now use `docker` directly, or `boot2docker ssh` to log into the VM.

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$

然后输入docker:

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ docker
Usage: docker [OPTIONS] COMMAND [arg...]
       docker daemon [ --help | ... ]
       docker [ --help | -v | --version ]

A self-sufficient runtime for containers.

Options:

  -b, --bridge                                                          Attach containers to a virtual switch
  --config=%USERPROFILE%\.docker                                        Location of client config files
  -D, --debug                                                           Enable debug mode
  -H, --host=[]                                                         Daemon socket(s) to connect to
  -h, --help                                                            Print usage
  -l, --log-level=info                                                  Set the logging level
  --tls                                                                 Use TLS; implied by --tlsverify
  --tlscacert=%USERPROFILE%\.boot2docker\certs\boot2docker-vm\ca.pem    Trust certs signed only by this CA
  --tlscert=%USERPROFILE%\.boot2docker\certs\boot2docker-vm\cert.pem    Path to TLS certificate file
  --tlskey=%USERPROFILE%\.boot2docker\certs\boot2docker-vm\key.pem      Path to TLS key file
  --tlsverify=true                                                      Use TLS and verify the remote
  -v, --version                                                         Print version information and quit

Commands:
    attach    Attach to a running container
    build     Build an image from a Dockerfile
    commit    Create a new image from a container's changes
    cp        Copy files/folders between a container and the local filesystem
    create    Create a new container
    diff      Inspect changes on a container's filesystem
    events    Get real time events from the server
    exec      Run a command in a running container
    export    Export a container's filesystem as a tar archive
    history   Show the history of an image
    images    List images
    import    Import the contents from a tarball to create a filesystem image
    info      Display system-wide information
    inspect   Return low-level information on a container or image
    kill      Kill a running container
    load      Load an image from a tar archive or STDIN
    login     Register or log in to a Docker registry
    logout    Log out from a Docker registry
    logs      Fetch the logs of a container
    network   Manage Docker networks
    pause     Pause all processes within a container
    port      List port mappings or a specific mapping for the CONTAINER
    ps        List containers
    pull      Pull an image or a repository from a registry
    push      Push an image or a repository to a registry
    rename    Rename a container
    restart   Restart a container
    rm        Remove one or more containers
    rmi       Remove one or more images
    run       Run a command in a new container
    save      Save an image(s) to a tar archive
    search    Search the Docker Hub for images
    start     Start one or more stopped containers
    stats     Display a live stream of container(s) resource usage statistics
    stop      Stop a running container
    tag       Tag an image into a repository
    top       Display the running processes of a container
    unpause   Unpause all processes within a container
    update    Update resources of one or more containers
    version   Show the Docker version information
    volume    Manage Docker volumes
    wait      Block until a container stops, then print its exit code

Run 'docker COMMAND --help' for more information on a command.

可看到docker的各种命令,具体用法可参考: http://www.runoob.com/docker/docker-command-manual.html

报错一:

Error response from daemon: client is newer than server (client API version: 1.22, server API version: 1.20)

查看版本:

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ docker version
Client:
 Version:      1.10.0
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   590d5108
 Built:        Thu Feb  4 18:18:11 2016
 OS/Arch:      windows/amd64
Error response from daemon: client is newer than server (client API version: 1.22, server API version: 1.20)

将server的版本设置为客服端的版本:

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ export DOCKER_API_VERSION=1.20

再次查看不再报错,可显示完整的client和server版本信息:

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ docker version
Client:
 Version:      1.10.0
 API version:  1.20
 Go version:   go1.5.3
 Git commit:   590d5108
 Built:        Thu Feb  4 18:18:11 2016
 OS/Arch:      windows/amd64

Server:
 Version:      1.8.0
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   0d03096
 Built:        Tue Aug 11 17:17:40 UTC 2015
 OS/Arch:      linux/amd64

镜像

查看镜像:

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

上面显示镜像为空。

创建hello-world的镜像

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
65b27d3bd74d: Pulling fs layer
9f5834b25059: Pulling fs layer
65b27d3bd74d: Verifying Checksum
65b27d3bd74d: Download complete
9f5834b25059: Verifying Checksum
9f5834b25059: Download complete
65b27d3bd74d: Pull complete
9f5834b25059: Pull complete
Digest: sha256:fb158b7ad66f4d58aa66c4455858230cd2eab4cdf29b13e5c3628a6bfc2e9f05
Status: Downloaded newer image for hello-world:latest

再次查看镜像:

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              9f5834b25059        2 weeks ago         0 B

运行镜像

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ 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/

python

查找python相关库

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ docker search python
NAME                                   DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
python                                 Python is an interpreted, interactive, obj...   3814      [OK]
django                                 Django is a free web application framework...   784       [OK]
pypy                                   PyPy is a fast, compliant alternative impl...   162       [OK]
kaggle/python                          Docker image for Python scripts run on Kaggle   106                  [OK]
frolvlad/alpine-python3                The smallest Docker image with Python 3.5 ...   94                   [OK]
azuresdk/azure-cli-python              For official Azure CLI 2.0 builds, see htt...   37                   [OK]
centos/python-35-centos7               Platform for building and running Python 3...   33
arm32v7/python                         Python is an interpreted, interactive, obj...   32
amazon/aws-eb-python                   AWS Elastic Beanstalk Python Image              24
circleci/python                        Python is an interpreted, interactive, obj...   21
joyzoursky/python-chromedriver         Python with Chromedriver, for running auto...   19                   [OK]
centos/python-36-centos7               Platform for building and running Python 3...   14
centos/python-27-centos7               Platform for building and running Python 2...   12
iron/python                            Tiny Python Microcontainer                      9
microsoft/azure-functions-python3.6    Azure functions python image                    8                    [OK]
dockershelf/python                     Repository for docker images of Python. Te...   4                    [OK]
publicisworldwide/python-conda         Basic Python environments with Conda.           4                    [OK]
bitnami/python                         Bitnami Python Docker Image                     3                    [OK]
komand/python-plugin                   DEPRECATED: Komand Python SDK                   2                    [OK]
civisanalytics/civis-jupyter-python3   Custom Jupyter Notebook image for Python 3      2                    [OK]
centos/python-34-centos7               Platform for building and running Python 3...   2
civisanalytics/civis-jupyter-python2   Custom Jupyter Notebook image for Python 2.     1                    [OK]
qbtrade/python                         python 3.5.0 with requirements                  0
saagie/python                          Repo for python jobs                            0
openshift/python-33-centos7            DEPRECATED: A Centos7 based Python v3.3 im...   0

安装python3.7

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ docker pull python:3.7
3.7: Pulling from library/python
7494d6c99127: Pulling fs layer
91625a8bb3d1: Pulling fs layer
85aa73fb8281: Pulling fs layer
3885fb7cb6a1: Pulling fs layer
aba0ac73d38a: Pulling fs layer
6f2ae6b13c28: Pulling fs layer
6d983f4694d3: Pulling fs layer
f3cbf41ff683: Pulling fs layer
9eb9326b64f8: Pulling fs layer
253214bd8118: Pulling fs layer
d63a7e7f4d17: Pulling fs layer
e72018435fda: Pulling fs layer
c8b13b0f5899: Pulling fs layer
2b89411a969a: Pulling fs layer
c00804d4f8dd: Pulling fs layer
5170766652ea: Pulling fs layer
2b89411a969a: Verifying Checksum
2b89411a969a: Download complete
c8b13b0f5899: Verifying Checksum
c8b13b0f5899: Download complete
91625a8bb3d1: Verifying Checksum
91625a8bb3d1: Download complete
d63a7e7f4d17: Verifying Checksum
d63a7e7f4d17: Download complete
253214bd8118: Verifying Checksum
253214bd8118: Download complete
f3cbf41ff683: Verifying Checksum
f3cbf41ff683: Download complete
6d983f4694d3: Verifying Checksum
6d983f4694d3: Download complete
5170766652ea: Verifying Checksum
5170766652ea: Download complete
c00804d4f8dd: Verifying Checksum
c00804d4f8dd: Download complete
9eb9326b64f8: Verifying Checksum
9eb9326b64f8: Download complete
3885fb7cb6a1: Verifying Checksum
3885fb7cb6a1: Download complete
85aa73fb8281: Verifying Checksum
85aa73fb8281: Download complete
e72018435fda: Verifying Checksum
e72018435fda: Download complete
7494d6c99127: Verifying Checksum
7494d6c99127: Download complete
7494d6c99127: Pull complete
91625a8bb3d1: Pull complete
85aa73fb8281: Pull complete
3885fb7cb6a1: Pull complete
aba0ac73d38a: Verifying Checksum
aba0ac73d38a: Download complete
aba0ac73d38a: Pull complete
6f2ae6b13c28: Verifying Checksum
6f2ae6b13c28: Download complete
6f2ae6b13c28: Pull complete
6d983f4694d3: Pull complete
f3cbf41ff683: Pull complete
9eb9326b64f8: Pull complete
253214bd8118: Pull complete
d63a7e7f4d17: Pull complete
e72018435fda: Pull complete
c8b13b0f5899: Pull complete
2b89411a969a: Pull complete
c00804d4f8dd: Pull complete
5170766652ea: Pull complete
Digest: sha256:28c9956a820177d57f22a86c73397ac92dfe0dbb2b2359a402ec742a048c93a5
Status: Downloaded newer image for python:3.7

查看镜像:

lenovo@YXY-SZ-047 MINGW64 ~ (master)
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
python              3.7                 5170766652ea        8 days ago          0 B
hello-world         latest              9f5834b25059        2 weeks ago         0 B
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值