【有用】docker在windows下使用详情

在Windows下安装和使用Docker可以按照以下步骤进行:
在这里插入图片描述

  1. 安装 Docker Desktop
    系统要求
    • Windows 10 64-bit: Pro, Enterprise, or Education (1607 Anniversary Update, Build 14393 or later)
    • Windows 11 64-bit: Pro, Enterprise, or Education
    • Windows 10 Home 64-bit (版本2004和以上)
    • 硬件虚拟化支持
    安装步骤

  2. 下载 Docker Desktop 安装程序:
    • 访问 Docker官方下载页面。
    • 下载适用于Windows的Docker Desktop安装程序。

  3. 安装 Docker Desktop:
    • 双击下载的安装程序,按照提示进行安装。
    • 安装过程中,确保勾选了“Enable WSL 2 features”选项,以便启用WSL 2。

  4. 配置 WSL 2:
    • 如果你的系统还没有安装WSL 2,需要先进行安装。具体步骤可以参考WSL 2官方文档。
    • 安装完成后,在Docker Desktop的设置中启用“Use the WSL 2 based engine”选项。

  5. 启动 Docker Desktop:
    • 安装完成后,启动Docker Desktop。
    • 你可以在任务栏中的托盘区看到Docker的图标,表示Docker正在运行。

  6. 使用 Docker
    常用命令
    以下是一些常用的Docker命令及其解释:

  7. 检查 Docker 版本:docker --version

  8. 拉取镜像:docker pull <image_name>例如:docker pull nginx

  9. 运行容器:docker run -d -p 80:80 --name mynginx nginx这条命令会在后台启动一个Nginx容器,并将主机的80端口映射到容器的80端口。

  10. 查看运行中的容器:docker ps

  11. 停止容器:docker stop <container_id>

  12. 删除容器:docker rm <container_id>

  13. 查看镜像:docker images

  14. 删除镜像:docker rmi <image_id>
    示例:运行一个简单的Web应用

  15. 拉取一个Python镜像:docker pull python:3.9-slim

  16. 创建并运行一个容器:docker run -it --name mypythonapp -p 5000:5000 python:3.9-slim

  17. 进入容器:docker exec -it mypythonapp /bin/bash

  18. 在容器内创建一个简单的Flask应用:pip install flask
    echo “from flask import Flask” > app.py
    echo “app = Flask(name)” >> app.py
    echo “@app.route(‘/’)” >> app.py
    echo “def hello():” >> app.py
    echo " return ‘Hello, World!’" >> app.py
    echo “if name == ‘main’:” >> app.py
    echo " app.run(host=‘0.0.0.0’)" >> app.py

  19. 运行应用:python app.py

  20. 在浏览器中访问:
    • 打开浏览器,访问 http://localhost:5000,你应该会看到 “Hello, World!”。
    结论
    通过上述步骤,你可以在Windows下安装并使用Docker来运行容器化的应用。如果你遇到任何问题,可以查阅Docker官方文档或社区论坛,获取更多帮助。

注:GPT-4o新质生产力强大工具助力提高效率,具体可通过个人简介链接免费体验使用。

  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Docker on Windows by Elton Stoneman English | 14 July 2017 | ISBN: 1785281658 | 358 Pages | AZW3/EPUB/MOBI/PDF (conv) | 23.77 MB Key Features Start building applications as Docker images and running containers in a Windows production environment Design and implement distributed applications that run across multiple networked containers Build a full Continuous Deployment pipeline for a .NET Core application running on Windows Book Description Docker has become hugely popular because it offers benefits at all stages of software design and delivery. Until recently, it was impossible to use a Windows Server platform to host the Docker Engine without adding an additional layer of virtualization. Starting with Windows Server 2016, you are able to use Docker on Windows and take advantage to easily build, deploy, and run Windows Containers. From building and running simple images to designing and implementing distributed applications, this book will teach everything you need to know while using Docker on Windows. You will start by installing Docker on different versions of Windows and Windows Server, and run a simple container to verify that the setup is working correctly. You will see how to build Docker images with a Dockerfile for a simple website, and then run it on Windows. Moving on, we'll cover the practical usage of Docker and the tools in the Docker ecosystem, such as Docker Compose, Docker Trusted Registry, and Docker Swarm Mode. Then, you'll be able to apply that knowledge by building a full continuous deployment pipeline for a .NET Core application running on Windows. We'll also dive deep into some of the core features of Docker, such as networking and security. At the end of the book, you'll be guided through a business case that will help you practically implement Docker in a real-world scenario. What you will learn Understand how Docker works, build images, and run containers Run Docker on different versions of Windows, and on the cloud with Azure Des
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fighting的码农(zg)-GPT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值