1. 程式人生 > 實用技巧 >部署Nginx

部署Nginx

搜尋映象

網頁搜尋映象

建議在docker hub進行搜尋,可以看到幫助文件。

開啟檢視映象詳細資訊

命令搜尋映象

docker search nginx

下載映象

docker pull nginx

檢視下載的映象

docker images

啟動映象

docker run -d --name=nginx01 -p 3344:80 nginx

-d #後臺執行

--name #給容器起名

-p #暴露埠(宿主機埠:容器內部埠)

檢視執行容器

docker ps

請求測試

curl localhost:3344

進入容器

docker exec -it nginx01 /bin/bash

進入容器,搜尋nginx,檢視nginx配置檔案,退出容器,停止容器,再次訪問測試

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STAT
370ce844910c        nginx               "/docker-entrypoint.…"   17 minutes ago      Up 1
[root@localhost ~]# docker exec -it nginx01 /bin/bash
root@370ce844910c:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@370ce844910c:/# cd /etc/nginx/
root@370ce844910c:/etc/nginx# ls
conf.d		koi-utf  mime.types  nginx.conf   uwsgi_params
fastcgi_params	koi-win  modules     scgi_params  win-utf
root@370ce844910c:/etc/nginx# exit
exit
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
370ce844910c        nginx               "/docker-entrypoint.…"   19 minutes ago      Up 19 minutes       0.0.0.0:3344->80/tcp   nginx01
[root@localhost ~]# docker stop 370ce844910c
370ce844910c
[root@localhost ~]#

停止容器後便無法訪問nginx