docker run --name nginx -p 80:80 -d nginx
时间: 2023-11-13 09:35:16 浏览: 54
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`。
docker run -d -P --name nginx2 -v /home/nginx:/usr/share/nginx/html nginx
docker run -d -P --name nginx2 -v /home/nginx://share/nginx/html nginx 是一个用于在Docker中运行NGINX容器的命令。让我为您解释一下每个参数的含义:
1. -d:这个参数表示在后台运行容器,即以守护进程的方式运行。
2. -P:这个参数表示将容器内部的网络端口映射到主机上的随机端口。这样可以方便地访问容器内部的服务。
3. --name nginx2:这个参数指定了容器的名称,即将创建的容器的名称为nginx2。
4. -v /home/nginx:/usr/share/nginx/html:这个参数表示将主机上的目录 /home/nginx 挂载到容器内部的目录 /usr/share/nginx/html。这样可以实现主机和容器之间的文件共享。
5. nginx:这个参数表示要使用的镜像名称,即使用官方提供的NGINX镜像。
通过以上命令,您将在Docker中创建一个名为nginx2的NGINX容器,并将主机上的 /home/nginx 目录挂载到容器内部的 /usr/share/nginx/html 目录,从而实现文件共享。同时,容器将以后台守护进程的方式运行,并将容器内部的网络端口映射到主机上的随机端口,以便访问NGINX服务。