一、docker部署nginx
1.1 docker安装配置nginx
1.1.1 总体步骤
· 搜索镜像
· 拉取镜像
· 查看镜像
· 启动容器
· 服务端口映射
· 停止容器
· 移除容器
1.1.2 基础操作
1 、搜索nginx镜像
[ root@docker ~]
2 、拉取nginx镜像
[ root@docker ~]
3 、查看镜像
[ root@docker ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 18 months ago 141MB
4 、镜像改名
[ root@docker ~]
[ root@docker ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 18 months ago 141MB
xxqops.icu/nginx latest 605c77e624dd 18 months ago 141MB
5 、删除旧镜像
[ root@docker ~]
Untagged: nginx:latest
Untagged: nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
[ root@docker ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
xxqops.icu/nginx latest 605c77e624dd 18 months ago 141MB
1.1.3 启动容器
1 、启动容器依赖目前的镜像
[ root@docker ~]
[ root@docker ~]
[ root@docker data]
8ee4e3736f622541657fcd32db144b5621bc8f1abcc5d7976e07853a61f7609d
启动参数:
2 、查看映射是否正确
[ root@docker ~]
total 4
-rw-r--r-- 1 root root 0 Jul 14 16 :34 access.log
-rw-r--r-- 1 root root 626 Jul 14 16 :34 error.log
3 、访问nginx
[ root@docker ~]
[ root@docker ~]
[ root@docker ~]
"IPAddress" : "172.17.0.2" ,
[ root@docker ~]
hello world docker world
4 、进入容器
[ root@docker ~]
root@8ee4e3736f62:~
hello world docker world
二、docker部署自家官网-1
1.1 同步nginx的配置到docker服务器
[ root@nginx-server ~]
[ root@nginx-server ~]
1.2 同步webhp项目
[ root@nginx-server ~]
1.3 查看webhp项目的配置
[ root@docker ~]
server {
listen 8000 ;
listen [ ::] :8000;
server_name _;
root /root/webhp/;
index index.html;
access_log /data/log/nginx/www_access.log;
error_log /data/log/nginx/www_error.log;
location / {
try_files $uri $uri / /index.html;
}
location = /HCIP.jpg {
}
}
1.4 启动容器
[ root@docker ~]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abc4b0ff2df0 xxqops.icu/nginx:latest "/docker-entrypoint.…" 5 seconds ago Exited ( 1 ) 4 seconds ago nginx-webhp
[ root@docker ~]
2023 /07/14 09:24:30 [ emerg] 1
nginx: [ emerg] mkdir( ) "/data/www/proxy_temp_dir" failed ( 2 : No such file or directory)
[ root@docker ~]
1.5 访问前端
1 、查看容器状态
[ root@docker ~]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e26ae699ffce xxqops.icu/nginx:latest "/docker-entrypoint.…" 17 seconds ago Up 17 seconds 80 /tcp, 0.0 .0.0:8000-> 8000 /tcp nginx-webhp
[ root@docker ~]
tcp6 0 0 :::8000 :::* LISTEN 3330 /docker-proxy
2 、访问页面
[ root@docker ~]
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 14 Jul 2023 09:28:32 GMT
Content-Type: text/html; charset = utf-8
Content-Length: 8109
Last-Modified: Fri, 14 Jul 2023 09:09:42 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "64b110d6-1fad"
Accept-Ranges: bytes
1.6 基于webhp创建新镜像
1 、基于webhp前端容器创建新的镜像
[ root@docker ~]
sha256:9502210494f14ff510843fc8a66349f3dc77a5231b4754383f67cf675ccb55ff
2 、基于构建的新的image创建新的容器
[ root@docker ~]
三、docker部署自家官网-2
1.1 运行新的空白的nginx容器
1 、运行新的空白的nginx容器
[ root@docker ~]
1d8b95b9ca60fea36f104f1ad7ac14c268a52f871bbc8ec971d5ffe737214193
[ root@docker ~]
< title> Welcome to nginx! < /title>
1.2 通过copy的方式把配置和webhp弄进去
[ root@docker ~]
[ root@docker ~]
1.3 进入容器查看copy是否成功
root@1d8b95b9ca60:~/webhp
ls: cannot access '/root/webhp/' : Operation not permitted
root@1d8b95b9ca60:~/webhp
164K ./HCIP.jpg
4 .0K ./README.md
8 .0K ./index.html
776K ./static
4 .0K ./学习css.html
4 .0K ./学习html.html
4 .0K ./学习表格和表单.html
4 .0K ./模板css.css
root@1d8b95b9ca60:~/webhp
4 .0K /etc/nginx/conf.d
0 /etc/nginx/default.d
4 .0K /etc/nginx/fastcgi.conf
4 .0K /etc/nginx/fastcgi.conf.default
4 .0K /etc/nginx/fastcgi_params
4 .0K /etc/nginx/fastcgi_params.default
4 .0K /etc/nginx/http.conf
4 .0K /etc/nginx/koi-utf
4 .0K /etc/nginx/koi-win
8 .0K /etc/nginx/mime.types
8 .0K /etc/nginx/mime.types.default
0 /etc/nginx/modules
4 .0K /etc/nginx/nginx.conf
4 .0K /etc/nginx/nginx.conf.bak
4 .0K /etc/nginx/nginx.conf.default
4 .0K /etc/nginx/proxy_webhp
4 .0K /etc/nginx/proxy_webhp.bak
4 .0K /etc/nginx/scgi_params
4 .0K /etc/nginx/scgi_params.default
4 .0K /etc/nginx/uwsgi_params
4 .0K /etc/nginx/uwsgi_params.default
4 .0K /etc/nginx/win-utf
1.4 重启nginx
root@1d8b95b9ca60:~/webhp
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2023 /07/14 12 :55:20 [ emerg] 59
nginx: [ emerg] mkdir( ) "/data/www/proxy_temp_dir" failed ( 2 : No such file or directory)
root@1d8b95b9ca60:~/webhp
root@1d8b95b9ca60:~/webhp
root@1d8b95b9ca60:~/webhp
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@1d8b95b9ca60:/etc/nginx
root@1d8b95b9ca60:/etc/nginx
HTTP/1.1 200 OK
1.5 封装成新的镜像
[ root@docker ~]
sha256:4617b729de6518b4ccb9ab1547341caeda42f8d4405b60ce6ab4bf4f34eebbaa
[ root@docker ~]
xxqops.icu/nginx v1.0 4617b729de65 3 minutes ago 147MB
xxqops.icu/nginx latest 605c77e624dd 18 months ago 141MB
1.6 利用新镜像直接启动前端服务器
1 、启动容器
[ root@docker ~]
[ root@docker ~]
[ root@docker ~]
total 4
-rw-r--r-- 1 root root 0 Jul 14 21 :05 access.log
-rw-r--r-- 1 root root 0 Jul 14 21 :05 error.log
-rw-r--r-- 1 root root 1244 Jul 14 21 :05 www_access.log
-rw-r--r-- 1 root root 0 Jul 14 21 :05 www_error.log
2 、查看镜像的层数
[ root@docker ~]