centos7-docker安装nginx
# 查看当前镜像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest a347a5928046 2 weeks ago 545MB
centos latest 300e315adb2f 4 weeks ago 209MB
hello-world latest bf756fb1ae65 12 months ago 13.3kB
# 搜索nginx镜像----search
docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 14270 [OK]
mailu/nginx Mailu nginx frontend 8 [OK]
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 7 [OK]
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
wodby/nginx Generic nginx 1 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 1 [OK]
#下载nginx镜像----pull latest表示最新版本 如果需要指定版本请上docker官网
docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
6ec7b7d162b2: Already exists
cb420a90068e: Pull complete
2766c0bf2b07: Pull complete
e05167b6a99d: Pull complete
70ac9d795e79: Pull complete
Digest: sha256:4cf620a5c81390ee209398ecc18e5fb9dd0f5155cd82adcbae532fec94006fb9
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
#下载完之后查看镜像,已经有了nginx
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest a347a5928046 2 weeks ago 545MB
nginx latest ae2feff98a0c 3 weeks ago 133MB
centos latest 300e315adb2f 4 weeks ago 209MB
hello-world latest bf756fb1ae65 12 months ago 13.3kB
# 运行镜像run
docker run -d --name nginx-web -p 81:80 ae2feff98a0c
a8e0c92ac982b90ed825f7d2b81aa7c489ce2f59b4ca99695ab1dfc800fb5335
# 运行镜像run
# 以后台方式启动 -d
# 起一个容器别名方便区分 --name nginx-web
# 暴露一个端口 -p 81:80 81代表宿主机的,映射到容器nginx服务的80端口
# 镜像id或者镜像名 ae2feff98a0c 或者nginx
# 启动后查看当前状态
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8e0c92ac982 ae2feff98a0c "/docker-entrypoint.…" 7 seconds ago Up 6 seconds 0.0.0.0:81->80/tcp nginx-web
# 宿主机运行测试
curl 192.168.198.129:81
<title>Welcome to nginx!</title>
# 进入容器
docker exec -it nginx-web /bin/bash
# 退出容器
root@a8e0c92ac982:/etc# exit
# 查看当前运行中的容器
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8e0c92ac982 ae2feff98a0c "/docker-entrypoint.…" About an hour ago Up About an hour 0.0.0.0:81->80/tcp nginx-web
# 停止容器
docker stop a8e0c92ac982

浙公网安备 33010602011771号