docker安装nginx
1.拉取镜像docker pull nginx2.创建容器docker run -d -it --name jsjnginx nginx-d 在后台运行容器,并且打印容器id-i 以交互模式运行容器,通常与 -t 同时使用-t 为容器重新分配一个伪输入终端,通常与 -i 同时使用3.检查容器是否启动[root@VM-0-10-centos ~]# docker psCONTAINER IDIMAG
·
1.拉取镜像
docker pull nginx
2.创建容器
docker run -d -it --name jsjnginx nginx
-d 在后台运行容器,并且打印容器id
-i 以交互模式运行容器,通常与 -t 同时使用
-t 为容器重新分配一个伪输入终端,通常与 -i 同时使用
3.检查容器是否启动
[root@VM-0-10-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
94a649581137 nginx "/docker-entrypoint.…" 59 seconds ago Up 58 seconds 80/tcp jsjnginx
4.拷贝nginx配置文件
a.进入容器
[root@VM-0-10-centos ~]# docker exec -it jsjnginx bash
root@94a649581137:/#
b.查看配置文件default.conf在哪里
root@94a649581137:/# find / -name nginx
/usr/share/doc/nginx
/usr/share/nginx
/usr/lib/nginx
/usr/sbin/nginx
find: '/proc/1/map_files': Operation not permitted
find: '/proc/31/map_files': Operation not permitted
find: '/proc/32/map_files': Operation not permitted
find: '/proc/38/map_files': Operation not permitted
/etc/init.d/nginx
/etc/default/nginx
/etc/logrotate.d/nginx
/etc/nginx
/var/log/nginx
/var/cache/nginx
root@94a649581137:/#
b.查看结果
[root@VM-0-10-centos ~]# docker exec -it jsjnginx bash
root@94a649581137:/# find / -name nginx
/usr/share/doc/nginx
/usr/share/nginx
/usr/lib/nginx
/usr/sbin/nginx
find: '/proc/1/map_files': Operation not permitted
find: '/proc/31/map_files': Operation not permitted
find: '/proc/32/map_files': Operation not permitted
find: '/proc/38/map_files': Operation not permitted
/etc/init.d/nginx
/etc/default/nginx
/etc/logrotate.d/nginx
/etc/nginx
/var/log/nginx
/var/cache/nginx
root@94a649581137:/# cd /etc/nginx
root@94a649581137:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
root@94a649581137:/etc/nginx# cd conf.d
root@94a649581137:/etc/nginx/conf.d# ls
default.conf
root@94a649581137:/etc/nginx/conf.d#
5.用exit退出到宿主机,在宿主机上创建 /home/nginx/conf的文件目录。
mkdir -p /home/nginx/conf
6.把nginx中的配置文件拷贝出来
docker cp jsjnginx:/etc/nginx/conf.d /home/nginx/conf/conf.d
jsjnginx是容器名称
/etc/nginx/conf.d是配置文件default.conf在容器中的地址
/home/nginx/conf/conf.d是要映射的宿主机地址
7.重建一个Nginx
[root@VM-0-10-centos ~]# docker stop jsjnginx #停止容器
jsjnginx
[root@VM-0-10-centos ~]# docker rm jsjnginx #删除容器
jsjnginx
[root@VM-0-10-centos ~]# docker run -d -p 59420:80 --name allnginx -v /home/nginx/conf/conf.d:/etc/nginx/conf.d -v /home/nginx/data:/data nginx
e46638c7c93769d2aaed53cb6dbcc78f195df535b59b539c5e659b58d78e9dd2
-d :后台运行
-p 59420:80 : 将主机59420端口映射到容器80端口 容器内端口地址在nginx配置上那个地址
-v /home/nginx/conf/conf.d:/etc/nginx/conf.d :将刚才复制出来的配置文件映射到容器的配置文件处
-v /home/nginx/data:/nginxdata : 在拉个映射出来放前端页面文件
8. 把前端的静态资源放好

9.配置nginx文件
cd /home/nginx/conf/conf.d/ #进入本地主机配置文件存放的地址
vi default.conf #编辑配置问津
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /data;
index index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)