当前位置:   article > 正文

windows10 装docker和docker compose_windows安装docker-compose

windows安装docker-compose

一.windows环境准备

开启过程中的问题,进入bios修复

二.docker下载安装

1.下载

Docker Desktop: The #1 Containerization Tool for Developers | Docker

下载最新版有问题,下载老版本试试

Docker Desktop release notes | Docker Docs

2.安装

三.docker测试

1.部署一个nginx

  1. C:\Users\Administrator>docker pull nginx
  2. Using default tag: latest
  3. latest: Pulling from library/nginx
  4. af107e978371: Pull complete
  5. 336ba1f05c3e: Pull complete
  6. 8c37d2ff6efa: Pull complete
  7. 51d6357098de: Pull complete
  8. 782f1ecce57d: Pull complete
  9. 5e99d351b073: Pull complete
  10. 7b73345df136: Pull complete
  11. Digest: sha256:2bdc49f2f8ae8d8dc50ed00f2ee56d00385c6f8bc8a8b320d0a294d9e3b49026
  12. Status: Downloaded newer image for nginx:latest
  13. docker.io/library/nginx:latest
  14. What's Next?
  15. View summary of image vulnerabilities and recommendations → docker scout quickview nginx
  16. C:\Users\Administrator>docker image ls
  17. REPOSITORY TAG IMAGE ID CREATED SIZE
  18. nginx latest d453dd892d93 2 months ago 187MB
  19. C:\Users\Administrator>docker run --name my-nginx -d -p 80:80 nginx

2.部署一个nginx并挂载到本地路径

1. 替换C:/docker/nginx 为你自己的目录路径。此命令会将主机的 80 端口与容器的 80 端口关联起来,因此当你通过浏览器访问主机 IP 地址时,就能看到挂载的网站内容。

2.创建的目录挂载到容器的 /usr/share/nginx/html 目录

  1. C:\Users\Administrator>docker run --name my-nginx1 -d -p 80:80 -v C:/docker/nginx:/usr/share/nginx/html nginx
  2. ee12f7dab38e5ff47b1cc186467c72c3bbe6398d5931049a0c85a4546baeaa5b
  3. C:\Users\Administrator>docker ps
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  5. ee12f7dab38e nginx "/docker-entrypoint.…" 5 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp my-nginx1

四.docker compose安装

1.什么是 Docker Compose ?

Docker Compose是Docker官方提供的一个用于定义和运行多容器Docker应用程序的工具。通过一个单独的docker-compose.yml配置文件,开发人员可以定义应用程序的服务、网络、卷等相关配置,并通过简单的命令一键启动整个应用程序。这种方式使得开发、测试和部署多容器应用变得更加轻松,同时保持了配置的一致性。Docker Compose的出现为复杂的容器编排提供了简便的解决方案,使得开发人员能够更专注于应用程序的开发和优化。

2.下载 Docker Compose

官方安装文档:https://docs.docker.com/desktop/install/windows-install/

版本选择下载地址:https://github.com/docker/compose/releases

3.安装Docker Compose

放到指定路径

 配置环境变量

 docker-compose --version

4.docker-compose部署一个nginx

新建一个文件docker-compose.yml 

解释如下:映射容器的80端口到宿主机的8081端口,挂载本地路径C:/docker/nginx/html到容器的nginx页面文件路径

  1. version: '3'
  2. services:
  3. nginx:
  4. image: nginx
  5. ports:
  6. - "8081:80"
  7. volumes:
  8. - C:/docker/nginx/html:/usr/share/nginx/html
  9. - C:/docker/nginx/nginx.conf:/ext/nginx/nginx.conf
  10. - C:/docker/nginx/log:/var/log/nginx

启动命令

  1. C:\docker 的目录
  2. 2024/01/10 11:39 docker-compose.yml
  3. 2024/01/10 11:38 <DIR> nginx
  4. C:\docker>docker-compose up -d
  5. [+] Running 1/0
  6. [+] Running 1/2ker_default Created 0.0s
  7. [+] Running 1/2ker_default Created 0.0s
  8. [+] Running 1/2ker_default Created 0.0s
  9. [+] Running 1/2ker_default Created 0.0s
  10. [+] Running 1/2ker_default Created 0.0s
  11. [+] Running 2/2ker_default Created 0.0s
  12. ✔ Network docker_default Created 0.0s - Container docker-nginx-1 Starting 0.6s
  13. ✔ Container docker-nginx-1 Started

停止命令

  1. C:\docker>docker-compose down
  2. [+] Running 1/1
  3. [+] Running 1/2ocker-nginx-1 Removed 0.5s
  4. [+] Running 2/2ocker-nginx-1 Removed 0.5s
  5. ✔ Container docker-nginx-1 Removed 0.5s - Network docker_default Removing 0.2s
  6. ✔ Network docker_default Removed

测试结果

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/403884
推荐阅读
相关标签
  

闽ICP备14008679号