您不需要ssh进入nginx容器并发出
sudo systemctl start nginx command
. 一旦启动容器,nginx将自动启动。
这是一个简单的
docker-compose.yml
文件启动nginx服务:
version: '3'
services:
nginxserver:
image: nginx
ports:
- "8080:80"
volumes:
- /opt/nginx:/usr/share/nginx/html:rw
运行以下命令启动服务:
docker-compose -f docker-compose.yml up
服务将启动,并且可以在本地主机上访问它。
http://localhost:8080/
(见上述yaml文件中的端口映射部分)
另请参见yaml文件中的卷映射部分。本地目录
/opt/nginx
映射到容器目录
/usr/share/nginx/html
,这是默认的nginx根目录。
更换
/选择/nginx
无论您想要什么本地目录,只需将
index.html
在那里进行测试:
<html>
<body>
Hello world!
</body>
</html>
立即访问
http://localhost:8080/
你应该看到世界的问候语。使用该本地目录部署文件。