1、部署nginx
# 1. 搜索镜像
docker search nginx# 2. 下载镜像
docker pull nginx# 3. 查看镜像是否下载成功
docker image# 4. 启动容器(-d:后台运行 --name:容器名 -p:暴露端口 宿主机端口3344:容器端口80)
dockerrun -d --name nginx01 -p 3344:80 nginx# 5. 查看容器是否启动
docker ps# 6. 本机测试
curl localhost:3344
完整代码:
#1、 搜索镜像
[root@iZ2vcfsvipso9tjpqp6fuyZ /]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 18636 [OK]
unit Official build of NGINX Unit: Universal Web … 6 [OK]
nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 90
nginxproxy/acme-companion Automated ACME SSL certificate generation fo… 116
bitnami/nginx Bitnami nginx Docker Image 165 [OK]
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 29 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 96
nginxproxy/docker-gen Generate files from docker container meta-da… 12
kasmweb/nginx An Nginx image based off nginx:alpine and in… 6
rancher/nginx-ingress-controller 11
rancher/nginx-ingress-controller-defaultbackend 2
bitnami/nginx-exporter 3
rancher/nginx 2
rapidfort/nginx-ib RapidFort optimized, hardened image for NGIN… 10
rapidfort/nginx RapidFort optimized, hardened image for NGINX 14
vmware/nginx-photon 1
bitnami/nginx-ldap-auth-daemon 3
rapidfort/nginx-official RapidFort optimized, hardened image for NGIN… 10
vmware/nginx 2
rancher/nginx-conf 0
linuxserver/nginx An Nginx container, brought to you by LinuxS… 203
nginxproxy/forego Foreman in Go 0
bitnamicharts/nginx 0
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 75 [OK]
bitnami/nginx-intel# 2、下载镜像 1
[root@iZ2vcfsvipso9tjpqp6fuyZ /]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest# 3、查看镜像是否下载成功
[root@iZ2vcfsvipso9tjpqp6fuyZ /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 17 months ago 141MB# 4、启动容器 (-d: 后台启动 --name: 容器的别名 -p: 暴露端口 宿主主机端口号3344::容器端口号80 )
[root@iZ2vcfsvipso9tjpqp6fuyZ /]# docker run -d --name nginx01 -p 3344:80 nginx
550741303b309f0b3e108b122b58de56102a78adb2129fede58823cdfee33006# 5.、查看容器是否启动
[root@iZ2vcfsvipso9tjpqp6fuyZ /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
550741303b30 nginx "/docker-entrypoint.…" 8 seconds ago Up 8 seconds 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx01# 6.、本机测试
[root@iZ2vcfsvipso9tjpqp6fuyZ /]# curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
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># 7、进入容器
[root@iZ2ze3zdx4jq8v6hetjjuxZ home]# docker exec -it nginx01 /bin/bash
root@1f9dbdf7f36d:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@1f9dbdf7f36d:/# cd /etc/nginx/
root@1f9dbdf7f36d:/etc/nginx# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf# 8、停止容器
[root@iZ2vcfsvipso9tjpqp6fuyZ /]# docker ps -aq
550741303b30
[root@iZ2vcfsvipso9tjpqp6fuyZ /]# docker stop 550741303b30
550741303b30