docker run -d --name my-nginx -p 8080:80 nginx的含义
时间: 2024-06-07 21:10:08 浏览: 12
这个命令会在 Docker 中运行一个名为 my-nginx 的容器,并将容器内部的 80 端口映射到宿主机的 8080 端口。这样,当你访问本地机器的 8080 端口时,它就会将请求转发到容器内部的 80 端口。容器使用的镜像是 nginx,这意味着它会从 Docker Hub 上下载并运行 nginx 镜像。选项 -d 是让容器在后台运行。
相关问题
docker run --name nginx -p 80:80 -d nginx
This command creates and runs a Docker container named "nginx" with the official Nginx image. It also maps the host machine's port 80 to the container's port 80 using the "-p 80:80" option, allowing access to the Nginx web server from the host machine's web browser. Finally, the "-d" option runs the container in detached mode, meaning it runs in the background, allowing the user to continue using the terminal.
docker run -d -p 8801:80 --name nginx nginx/laster docker: Error response from daemon: No command specified.
这个错误信息提示你没有指定容器启动后要执行的命令,因为 `nginx` 镜像没有默认的启动命令。
你可以在 `docker run` 命令后面添加一个命令,比如:
```
docker run -d -p 8801:80 --name my-nginx nginx:latest nginx -g "daemon off;"
```
这个命令将创建一个名为 `my-nginx` 的容器,映射容器内部的 80 端口到主机的 8801 端口,并执行 `nginx -g "daemon off;"` 命令作为容器的启动命令。
注意,`nginx -g "daemon off;"` 命令是在容器内部执行的,不需要在命令行中添加 `docker exec`。