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

相关推荐
Olrookie13 小时前
若依前后端分离版学习笔记(二十)——实现滑块验证码(vue3)
java·前端·笔记·后端·学习·vue·ruoyi
ZHE|张恒13 小时前
Docker 安装 RabbitMQ
docker·rabbitmq
倚栏听风雨14 小时前
java.lang.SecurityException异常
java
星河队长14 小时前
VS创建C++动态库和C#访问过程
java·c++·c#
鼠鼠我捏,要死了捏14 小时前
Java虚拟线程原理与性能优化实战
java·performance-optimization·virtual-thread
艾菜籽14 小时前
Spring MVC练习:留言板
java·spring·mvc
左灯右行的爱情15 小时前
4-Spring SPI机制解读
java·后端·spring
Code小翊15 小时前
C语言bsearch的使用
java·c语言·前端
yong999015 小时前
C#驱动斑马打印机实现包装自动打印
java·数据库·c#
好记忆不如烂笔头abc15 小时前
linux系统记录登录用户的所有操作
java·linux·服务器