当前位置:   article > 正文

Docker -- m1芯片 macOS 安装 nginx - 03_mac m1 安装nginx

mac m1 安装nginx

一、安装docker提前准备

查看 d o c k e r \color{#FF7D00}{docker} docker版本:在 c o m m e n t \color{#FF7D00}{comment} comment 中输入 docker -version返回

# 出现以下信息
Docker version 20.10.14, build a224086
  • 1
  • 2

显示 d o c k e r \color{#FF7D00}{docker} docker具体信息:在 c o m m e n t \color{#FF7D00}{comment} comment 中输入docker --info 返回

# 出现以下信息
unknown flag: --info
See 'docker --help'.

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default)
  -c, --context string     Name of the context to use to connect to the
                           daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level
                           ("debug"|"info"|"warn"|"error"|"fatal")
                           (default "info")
  
  -v, --version            Print version information and quit

Management Commands:
  builder     Manage builds
  buildx*     Docker Buildx (Docker Inc., v0.8.2)
  compose*    Docker Compose (Docker Inc., v2.4.1)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  sbom*       View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan*       Docker Scan (Docker Inc., v0.17.0)
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams 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 to files or directories 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

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

To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

二、下载nginx相关镜像

命令描述
docker pull nginx下载最新版 Nginx 镜像 (其实此命令就等同于 : docker pull nginx:latest)
docker pull nginx:xxx下载指定版本的 Nginx 镜像 (xxx 指具体版本号)

c o m m e n t \color{#FF7D00}{comment} comment 中输入 docker pull nginx:1.20.1

在这里插入图片描述

检查相关镜像

docker images
  • 1

在这里插入图片描述

三、运行相关容器

容器运行命令

d o c k e r   r u n − d − − n a m e   n g i n x − p   8088 : 80   n g i n x : 1.20.1 \color{#FF00FF}{docker \ run -d --name\ nginx -p\ 8088:80\ nginx:1.20.1} docker rundname nginxp 8088:80 nginx:1.20.1

  • docker 代表其中docker的二进制文件
  • run代表执行文件
  • -d代表后台运行容器,并返回容器ID,也即启动守护式容器
  • --name --name=“容器新名字”: 为容器指定一个名称
  • -P随机端口映射
  • -p 指定端口映射,有以下四种格
    • ip:hostPort:containerPort
    • ip::containerPor
    • hostPort:containerPor
    • containerPort
  • 8088:80 指定端口
  • nginx:1.20.1 指定nginx版本号

查看docker运行的情况

在这里插入图片描述

验证nginx是否启动成功

c u r l   h t t p : / / l o c a l h o s t : 8088 \color{#FF00FF}{curl\ http://localhost:8088} curl http://localhost:8088

在这里插入图片描述
注意: 其中curl 命令可以浅显的理解为–发送url的指令

修改nginx配置文件 nginx.conf

d o c k e r   e x e c   − i t   n g i n x   / b i n / b a s h \color{#FF00FF}{docker\ exec\ -it\ nginx\ /bin/bash} docker exec it nginx /bin/bash

  • docker exec -it进入容器内部执行命令
  • /bin/bash 进入配置目录

在这里插入图片描述

出现Docker:bash: vi: command not found 解决办法

# 这个命令的作用是:同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包
apt-get update
# 安装对应vim
apt-get install vim
# 若出现以下问题
bash:ping: command not found
# 安装对应安装包
apt-get install iputils-ping
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

四、运行并验证

浏览器输入 http://localhost:8088

在这里插入图片描述

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

闽ICP备14008679号