查找镜像文件
# 在Docker官方仓库中搜索Nginx镜像,Nginx镜像文件中只包含Nginx软件程序、数据文件 [root@node1 src]# docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 14587 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1984 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 810 [OK] jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 162 linuxserver/nginx An Nginx container, brought to you by LinuxS… 143 tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 117 [OK] jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 97 [OK] bitnami/nginx Bitnami nginx Docker Image 95 [OK] alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 89 [OK] jasonrivers/nginx-rtmp Docker images to host RTMP streams using NGI… 88 [OK] nginxdemos/hello NGINX webserver that serves a simple page co… 67 [OK] privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 49 [OK] nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 49 nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 32 schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK] staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 19 [OK] nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 16 centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 15 centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13 raulr/nginx-wordpress Nginx front-end for the official wordpress:f… 13 [OK] flashspys/nginx-static Super Lightweight Nginx Image 9 [OK] mailu/nginx Mailu nginx frontend 8 [OK] bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 8 [OK] ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 2 [OK] wodby/nginx Generic nginx 1 [OK]
下载镜像
# 从Docker官方仓库中下载Nginx镜像,下载至Docker宿主机上特定目录下 1)docker load <nginx.tar 2)docker pull nginx [root@node1 src]# docker pull nginx Using default tag: latest latest: Pulling from library/nginx 6f28985ad184: Pull complete 29f7ebf60efd: Pull complete 879a7c160ac6: Pull complete de58cd48a671: Pull complete be704f37b5f4: Pull complete 158aac73782c: Pull complete Digest: sha256:d2925188effb4ddca9f14f162d6fba9b5fab232028aa07ae5c1dab764dca8f9f Status: Downloaded newer image for nginx:latest docker.io/library/nginx:latest
查看已下载的或者导入的Nginx镜像文件的存储位置和列表信息
[root@node1 src]# ls /var/lib/docker/image/overlay2/ distribution imagedb layerdb repositories.json [root@node1 src]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 6084105296a9 5 days ago 133MB [root@node1 src]# docker images|grep -aiwE nginx nginx latest 6084105296a9 5 days ago 133MB
创建一台nginx容器
[root@node1 src]# docker run -itd -p 80:80 --name=scyun01 --privileged nginx:latest 86a654873eafd80594f067f40675d9d5404a4a14d2769cfbd9207cd8cbc17d18 Run,全新创建并且启动一台新容器; -i,interactive打开交互模式; -t,tty打开登录终端; -d,detach后台启动; -p,publish发布端口,将宿主机80(第一个)映射至容器的80端口;(DNAT)
查看虚拟机(容器)状态 与 ip地址
[root@node1 src]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 86a654873eaf nginx:latest "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp scyun01 #IP地址 [root@node1 src]# docker inspect 86a654873eaf |grep -ai ipaddr|tail -1|grep -aiowE "([0-9]{1,3}\.){3}[0-9]{1,3}" 172.17.0.2
查看容器id 或名称
[root@node1 src]# docker ps |awk 'NR>1 {print $1}' 86a654873eaf [root@node1 src]# docker ps |awk 'NR>1 {print $NF}' scyun01
进入容器内部
[root@node1 src]# docker exec -it $(docker ps |awk 'NR>1 {print $NF}') /bin/bash root@86a654873eaf:/#
修改默认配置文件
root@86a654873eaf:/etc/nginx/conf.d# sed -i -e '/#/d' -e '/^$/d' -e '/::/d' default.conf root@86a654873eaf:/etc/nginx/conf.d# sed -i -e 's/localhost/www.wscyun.com/g' -e 's#/usr/share/nginx/html#/data/webapps/#g' default.conf root@86a654873eaf:/etc/nginx/conf.d# cat default.conf server { listen 80; server_name www.wscyun.com; location / { root /data/webapps/; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /data/webapps/; } } root@86a654873eaf:/etc/nginx/conf.d# mkdir -p /data/webapps root@86a654873eaf:/etc/nginx/conf.d# cat >/data/webapps/index.html<<EOF > this is www.wscyun.com page > EOF root@86a654873eaf:/etc/nginx/conf.d# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful root@86a654873eaf:/etc/nginx/conf.d# nginx -s reload 2021/03/18 09:23:32 [notice] 60#60: signal process started
继续阅读
评论