m1芯片 macOS 安装 nginx
- 一、安装docker提前准备
- 二、下载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
显示 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/
二、下载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
三、运行相关容器
容器运行命令
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 run−d−−name nginx−p 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
四、运行并验证
浏览器输入 http://localhost:8088