[root@localhost my.Shells]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/redis latest 1e70071f4af4 6 weeks ago 106.7 MB
[root@localhost my.Shells]# docker pull nginx //下载nginx
Using default tag: latest
Trying to pull repository docker.io/library/nginx ...
latest: Pulling from docker.io/library/nginx
e7bb522d92ff: Pull complete
6edc05228666: Pull complete
cd866a17e81f: Pull complete
Digest: sha256:285b49d42c703fdf257d1e2422765c4ba9d3e37768d6ea83d7fe2043dad6e63d
[root@localhost my.Shells]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/nginx latest 3f8a4339aadd 3 weeks ago 108.5 MB
docker.io/redis latest 1e70071f4af4 6 weeks ago 106.7 MB
2.运行nginx
[root@localhost my.Shells]# docker run -p 8080:80 -d docker.io/nginx //将80端口映射为8080,或者80:80还是原先的80端口,不可以不写。
c0462d5e18783e20f9515108fa62ab0f2ac808ea85370a7c82aee9407abf4672
[root@localhost my.Shells]# netstat -anp | grep 8080 //端口已经开启了
tcp6 0 0 :::8080 :::* LISTEN 2529/docker-proxy-c
[root@localhost my.Shells]# docker ps //nginx已经在运行了
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" 4 minutes ago Up 4 minutes 0.0.0.0:8080->80/tcp angry_mccarthy
3.运行结果
[root@localhost my.Shells]# ./openFirewallPort.sh //先在防火墙上开一个端口
enter the port:
success
---openFirewallPort.sh-------
echo "enter the port: "
read port
firewall-cmd --add-port=$port/tcp
#下图已经成功访问到了
[root@localhost my.Shells]# docker ps //此时8080和8081都在运行
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fd8a0b5d138 docker.io/nginx "nginx -g 'daemon off" 4 minutes ago Up 4 minutes 0.0.0.0:8081->80/tcp suspicious_hypatia
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" About an hour ago Up 8 minutes 0.0.0.0:8080->80/tcp angry_mccarthy
[root@localhost my.Shells]# docker stop 1fd8a0b5d138 //停下8081
1fd8a0b5d138
[root@localhost my.Shells]# docker ps //就剩8080还在运行
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" About an hour ago Up 9 minutes 0.0.0.0:8080->80/tcp angry_mccarthy
[root@localhost my.Shells]# docker ps -a //可以看到8080在运行,8081已经Exited
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fd8a0b5d138 docker.io/nginx "nginx -g 'daemon off" 5 minutes ago Exited (0) 7 seconds ago suspicious_hypatia
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" About an hour ago Up 9 minutes 0.0.0.0:8080->80/tcp angry_mccarthy
[root@localhost my.Shells]#
[root@localhost my.Shells]# docker rm 1fd8a0b5d138 //移除这个进程进行了,注意运作着的进程是无法rm的,要先stop
1fd8a0b5d138