首先先在dockerhub上搜索一下nginx镜像,看一下上面的说明,自己再实操一遍~
dockerhub上面nginx的链接:
https://hub.docker.com/_/nginx
第一步:搜索镜像
#命令
docker search nginx
#测试
[root@xiaoxiao ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 13663 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1866 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 782 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 127
bitnami/nginx Bitnami nginx Docker Image 89 [OK]
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 88 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 82
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 75 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 59 [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 53 [OK]
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 40
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 32 [OK]
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK]
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 17
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 15
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 14
raulr/nginx-wordpress Nginx front-end for the official wordpress:f… 13 [OK]
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13
mailu/nginx Mailu nginx frontend 7 [OK]
bitwarden/nginx The Bitwarden nginx web server acting as a r… 7
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
第二步:拉取镜像
#命令
docker pull nginx
#调试
[root@xiaoxiao ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
bf5952930446: Pull complete
cb9a6de05e5a: Pull complete
9513ea0afb93: Pull complete
b49ea07d2e93: Pull complete
a5e4a503d449: Pull complete
Digest: sha256:b0ad43f7ee5edbc0effbc14645ae7055e21bc1973aee5150745632a24a752661
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
第三步:运行测试
#查看镜像有没有下载
[root@xiaoxiao ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 4bb46517cac3 2 weeks ago 133MB
centos latest 0d120b6ccaa8 2 weeks ago 215MB
#运行镜像
#-d 后台运行
#--name 给容器命名
#-p 宿主机端口:容器内端口
[root@xiaoxiao ~]# docker run -d --name nginx01 -p 3344:80 nginx
e85fbc7862d914725703c90777115a389e1149b5c35d4829be99f56e92d8f777
[root@xiaoxiao ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e85fbc7862d9 nginx "/docker-entrypoint.…" 6 seconds ago Up 5 seconds 0.0.0.0:3344->80/tcp nginx01
[root@xiaoxiao ~]# curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
端口暴露的概念:
需要在阿里云这一侧把安全组方通,然后就可以了
然后就可以访问了
接下来可以进入容器,查看配置文件
[root@xiaoxiao ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e85fbc7862d9 nginx "/docker-entrypoint.…" 15 minutes ago Up 15 minutes 0.0.0.0:3344->80/tcp nginx01
[root@xiaoxiao ~]# docker exec -it nginx01 /bin/bash
root@e85fbc7862d9:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@e85fbc7862d9:/# cd /etc/nginx/
root@e85fbc7862d9:/etc/nginx# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf
当把服务器停了之后,就进不去了
[root@xiaoxiao ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e85fbc7862d9 nginx "/docker-entrypoint.…" 19 minutes ago Up 19 minutes 0.0.0.0:3344->80/tcp nginx01
[root@xiaoxiao ~]# docker stop e85fbc7862d9
e85fbc7862d9
好啦,这就好了,今天就先到这里了