> For the complete documentation index, see [llms.txt](https://moekiwisama-1.gitbook.io/minecraft-docker/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://moekiwisama-1.gitbook.io/minecraft-docker/nginx/tong-guo-nginx-lai-xue-xi-yi-xie-chang-yong-can-shu.md).

# 参数 -p

通过 hello-world 的例子中，我们学会了第一个 docker 指令`docker run` ，它可以将一个 docker 镜像实例化成多个 docker 实例。

docker run 可以利用多个参数来控制实例的不同属性，比如端口转发，挂载目录，后台执行等。\
Nginx 是一个 Web 服务，它会开放一个 tcp 端口来处理 http 连接，docker 容器内的环境是相对封闭的，我们需要讲容器内的端口映射到容器外，才可以访问我们的 Nginx 服务。

```
docker run -p 8080:80 nginx
```

![](/files/-Mcxq-ag3X5tlAPJXDB4)

-p 参数可以将容器内的端口映射到容器外，`:`左侧表示容器外的端口，右侧表示容器内的端口。

Docker Hub 上的 Nginx 是一个运行在 80 端口的 Nginx 服务，我们可以通过将其映射到容器外（宿主机网卡）的 8080 端口来访问它。

Docker 默认会自动让防火墙通行这个 8080 端口，如果发现端口被阻挡，您可能需要在云服务器控制台打开这个端口，也可能需要在 ubuntu 上开启这个端口

```bash
sudo ufw allow 8080
```

打开浏览器访问宿主机的这个端口，可以看到服务正常被开启

![](/files/-McxrSW3cUGtggmW6atl)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://moekiwisama-1.gitbook.io/minecraft-docker/nginx/tong-guo-nginx-lai-xue-xi-yi-xie-chang-yong-can-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
