使用docker部署Nginx服务器

1.创建Dockerfile

[root@LIN-52E5F1B482B Desktop]# mkdir Dockerfile
[root@LIN-52E5F1B482B Desktop]# cd Dockerfile/

2.编辑Dockerfile

[root@LIN-52E5F1B482B Dockerfile]# vi Dockerfile
FROM nginx
RUN echo "hello nginx" > /usr/share/nginx/html/index.html

3.创建镜像

[root@LIN-52E5F1B482B Dockerfile]# docker build -t nginx:v1 .

4.创建容器

docker run -it --name mynginx -p 9999:80 nginx:v1

5.进入容器

[root@LIN-52E5F1B482B Dockerfile]# docker start c414fbeb39aa
c414fbeb39aa
[root@LIN-52E5F1B482B Dockerfile]# docker exec -it c414fbeb39aa /bin/bash 

6.查看index.html

root@c414fbeb39aa:/# cat /usr/share/nginx/html/index.html
hello nginx

访问路径:http://127.0.0.1:9999

posted @ 2021-10-29 14:53  厚我  阅读(159)  评论(0编辑  收藏  举报