Mac中Docker下载与安装

目录

Docker

下载

官网:https://www.docker.com/get-started/

或者

安装

配置

  • 这里我们选择 Accept
  • 选择默认配置就行,Docker 会自动设置一些大多数开发人员必要的配置。
  • 这里可以直接选择跳过


  • 出现以上的图标即可
  • 到这里并没有正真的完成

版本查询以及问题处理

如果不显示版本号,显示如下

shell 复制代码
docker --version
zsh:command not found:docker

那就要查看一下自己的配置文件中有没有配置docker

如果没有那就依次执行以下代码(先看看自己的配置文件是zshrc还是bash_profile)

shell 复制代码
echo 'export PATH=/Applications/Docker.app/Contents/Resources/bin:$PATH' >> ~/.zshrc
shell 复制代码
source ~/.zshrc

通过 docker info 命令 可以查看 Docker Client 端和 Server 端信息。
Client端显示包括 Docker 版本,当前的上下文,调试模式等。
Server 部分显示了 Docker 守护进程的信息,包括当前运行的容器数量、镜像数量等

shell 复制代码
Last login: Wed May  7 20:03:52 on ttys000
sunhaixin@bogon ~ % docker info
Client:
 Version:    28.0.4
 Context:    desktop-linux
 Debug Mode: false
 ......在此省略一些
Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 28.0.4
 ......在此省略一些

配置国内镜像

Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

因为没有配置国内镜像所以很容易导致链接失败

进入该目录

然后找到daemon.json

将以下代码放在这个位置

shell 复制代码
"registry-mirrors": [
            "https://docker.211678.top",
            "https://docker.1panel.live",
            "https://hub.rat.dev",
            "https://docker.m.daocloud.io",
            "https://do.nark.eu.org",
            "https://dockerpull.com",
            "https://dockerproxy.cn",
            "https://docker.awsl9527.cn"
      ]

添加完后重启docker软件即可

在Docker中安装软件

Nginx

  • 方式一:

  • 方式二:使用命令行

    shell 复制代码
    sudo docker pull nginx
  • 命名、指定端口并运行nginx

    shell 复制代码
    sudo docker run --name mynginx -p 8080:80 -d nginx

    --name mynginx 指定当前容器名称为 mynginx

    -p 8080:80 将容器的 80 端口映射到主机的 8080 端口

    -v ~/project/www:/usr/share/nginx/html 将主机的 ~/project/www 目录挂载到容器的 /www

    -v ~/project/nginx/conf.d:/etc/nginx/conf.d 将主机的 ~/project/nginx/conf.d 目录挂载到容器的 /etc/nginx/conf.d

    --link myphp:php 将 myphp 容器的网络并入 nginx 容器,实现容器间的通信

如果想将docker内的文件与docker外的文件相关关联

那么你可以在本地文件夹中创建对应文件

shell 复制代码
mkdir -p ~/project/nginx/www ~/project/nginx/logs ~/project/nginx/conf

www是项目路经

logs是nginx错误日志

conf 是nginx配置文件

可以看见nginx正常运行

接下来复制docker容器终端配置文件到宿主中

输入(ce1e83caf65f这个在上图查看安装中可见到)

shell 复制代码
docker cp ce1e83caf65f:/etc/nginx/nginx.conf ~/project/nginx/conf

可以查看一下原配置信息

接下来再运行一个新的(删除原来创建的nginx),前面是测试(开一个新的需要修改端口号和名字),输入如下:

shell 复制代码
docker run -d -p 8082:80 --name mynginx2 -v ~/project/nginx/www:/usr/share/nginx/html -v ~/project/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v ~/project/nginx/logs:/var/log/nginx nginx

进入www创建

shell 复制代码
cd ~/project/nginx/www
vim index.html
html 复制代码
#写一个hello world
<DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>my test docker</title>
</head>
<body>
<h1>hello world</h1>
</body>
</html>

在网页上输入http://localhost:8082/index.html,就能看到hello Wrold

相关推荐
小马爱打代码2 小时前
Spring Boot:模块化实战 - 保持清晰架构
java·spring boot·架构
小坏讲微服务2 小时前
SpringBoot4.0整合knife4j 在线文档完整使用
java·spring cloud·在线文档·knife4j·文档·接口文档·swagger-ui
8***Z892 小时前
springboot 异步操作
java·spring boot·mybatis
i***13243 小时前
Spring BOOT 启动参数
java·spring boot·后端
坚持不懈的大白3 小时前
后端:SpringMVC
java
IT_Octopus3 小时前
(旧)Spring Securit 实现JWT token认证(多平台登录&部分鉴权)
java·后端·spring
kk哥88993 小时前
Spring详解
java·后端·spring
S***26753 小时前
Spring Cloud Gateway 整合Spring Security
java·后端·spring
Tao____3 小时前
开源物联网平台
java·物联网·mqtt·开源·设备对接
遇到困难睡大觉哈哈3 小时前
Harmony os——ArkTS 语言笔记(四):类、对象、接口和抽象类
java·笔记·spring·harmonyos·鸿蒙