[Docker] Win10 installed and running Nginx mirror Docker

First, install Docker

Enter the official website: https://www.docker.com/products/docker-desktop

You may need to register to log, very simple.

Click Download Desktop for Mac and Windows into the download process

Select for windows, click Next Step to start the download.

I downloaded the package back more than 500 M, is quite large, double-click to install.

After the installation is complete, open cmd, run:

docker -v

Docker normally shows the current version number of the installation is successful.

 

Second, running Nginx Mirror

Netease into the first Cloud Mirror Center:

https://c.163yun.com/hub#/m/home/

 

Search nginx, 

 

We directly use the first date. After opening the direct point "copy", then execution in the terminal.

After performing pull nginx mirror, as shown success.

 

We can run:

docker images

To see if it really pulls success.

It can be seen already.

Next, we can run this nginx mirrored.

There are two ways to run a mirror: foreground, background.

Foreground

# Foreground nginx 
Docker RUN hub.c.163.com/library/nginx

Through the above command we run from the nginx, you will see what reaction the command line are gone (can be disabled via Ctrl + c).

We re-opened a cmd, run:

docker ps

To see if successfully run nginx.

We can see, nginx is running. After our previous window Ctrl + c to close it, and then run docker ps, the process will be closed.

Background process

# 后台运行 nginx 
# 增加参数 -d (detach) ,意思就是在后台运行镜像,返回镜像id

docker run -d hub.c.163.com/library/nginx

执行后,

可以看到第一个就是了。

进入容器内部

docker exec命令用于进入容器内部, -it 是这个命令的可选参数。-i 表示保证我们输入有效,-t 是给我们分配一个伪终端,多个参数可以连起来写,就成了  -it 

参数后边是容器名称或id,可以只输入开头的几个字符,它就会自动帮我们识别到。

那么接下来,我们运行命令:

docker exec -it 46a bash
# 46a 是我们上面运行的容器id头三位,您需要换成自己的

可以看到像是进入了一个新的主机。其实这确认是一个虚拟主机,因为我们的nginx本来就是运行在linux容器上,在这里我们可以执行linux的命令。

我们可以通过命令 

which nginx

来查看nginx在什么位置

然后可以通过 exit 命令退出到之前的主机。

exit

停止容器

# docker stop [容器id]
docker stop 46a

 

三、让浏览器可以访问

我们上面虽然启动了nginx,但你可能已经发现,我们在浏览器中无法访问容器中的nginx。

我们先停止已经启动的容器,再执行下面的命令:

docker run -d -p 8080:80 hub.c.163.com/library/nginx

如果windows弹出防火墙提示,点击允许访问。

这个时候我们再来通过netstat命令检查一下是否真的打开了 8080端口

netstat -na|grep 8080

可以看到,已经是监听状态了。我们直接在浏览器中打开试试。

 

 

完成。

 

Guess you like

Origin www.cnblogs.com/yangyxd/p/11239094.html