启动第一个docker容器
#1、获取镜像
#2、运行镜像,生成容器,应用就跑在了容器中。
Nginx web服务器,运行处一个80端口的网站
#在宿主机上,运行Nginx
1、开启服务器
2、在服务器上安装好运行Nginx所需的依赖关系
3、安装nginx yum install nginx -y
4、修改ngixnp配置文件
5、启动nginx
6、客户端访问nginx
比较耗时。。。。。。。。。。。
如果让你用docker运行nginx,该怎么玩?
1、获取镜像,获取是从配置好的dcoker镜像网站中,去拉取nginx镜像
#先搜索一下,镜像文件,是否存在
[root@Hadoop2 ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 18996 [OK]
unit Official build of NGINX Unit: Universal Web … 12 [OK]
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 121
nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo… 79
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 33
nginx/unit NGINX Unit is a dynamic web and application … 64
nginxinc/nginx-s3-gateway Authenticating and caching gateway based on … 2
nginx/nginx-ingress-operator NGINX Ingress Operator for NGINX and NGINX P… 1
nginxinc/amplify-agent NGINX Amplify Agent docker repository 1
nginx/nginx-quic-qns NGINX QUIC interop 1
nginxinc/ingress-demo Ingress Demo 4
nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 103
nginxproxy/acme-companion Automated ACME SSL certificate generation fo… 123
bitnami/nginx Bitnami nginx Docker Image 173 [OK]
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 29 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 98
nginxinc/nginmesh_proxy_debug 0
nginxproxy/docker-gen Generate files from docker container meta-da… 12
nginxinc/mra-fakes3 0
kasmweb/nginx An Nginx image based off nginx:alpine and in… 6
rancher/nginx-ingress-controller 11
nginxinc/ngx-rust-tool 0
nginxinc/mra_python_base 0
nginxinc/nginmesh_proxy_init 0
rancher/nginx-ingress-controller-defaultbackend 2
[root@Hadoop2 ~]#
#拉取,下载镜像
[root@Hadoop2 ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
360eba32fa65: Pull complete
c5903f3678a7: Pull complete
27e923fb52d3: Pull complete
72de7d1ce3a4: Pull complete
94f34d60e454: Pull complete
e42dcfe1730b: Pull complete
907d1bb4e931: Pull complete
Digest: sha256:6926dd802f40e5e7257fded83e0d8030039642e4e10c4a98a6478e9c6fe06153
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@Hadoop2 ~]#
#查看本地的docker镜像有那些
[root@Hadoop2 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f5a6b296b8a2 5 days ago 187MB
[root@Hadoop2 ~]#
#删除镜像的命令,其中使用了IMAGE ID,镜像ID;
docker rmi f5a6b296b8a2
#运行该nginx镜像,运行出具体的容器,然后这个容器中就可以跑一个nginx服务了;
#运行镜像的命令,参数如下
docker run 参数 镜像的名字/ID
# -d后台运行容器
# -p 80:80 端口映射,宿主机端口:容器内端口。若访问宿主机某个端口,相应的就会访问容器中对应端口。
docker run -d -p 80:80 nginx
#运行结果如下,docker run命令,会返回一个容器的id
[root@Hadoop2 ~]# docker run -d -p 80:80 nginx
00d67544a8726e38459036279a1c68839ec82f47fa3d49d95fb5cdd7b806239c
[root@Hadoop2 ~]#
#查看容器是否在运行
[root@Hadoop2 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
00d67544a872 nginx "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, :::80->80/tcp great_mayer
[root@Hadoop2 ~]#
#可以尝试停止容器,看下结果
docker stop 容器ID
#停止具体的容器进程
[root@Hadoop2 ~]# docker stop 00d67544a872
00d67544a872
[root@Hadoop2 ~]#
#查看看存在的进程
[root@Hadoop2 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Hadoop2 ~]#
docker stop
查看端口占用情况
[root@Hadoop2 ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 798/rpcbind
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2097/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1211/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1209/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1403/master
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2144/sshd: root@pts
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 6197/sshd: root@pts
tcp6 0 0 :::111 :::* LISTEN 798/rpcbind
tcp6 0 0 :::22 :::* LISTEN 1211/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1209/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1403/master
tcp6 0 0 ::1:6010 :::* LISTEN 2144/sshd: root@pts
tcp6 0 0 ::1:6011 :::* LISTEN 6197/sshd: root@pts
udp 0 0 192.168.122.1:53 0.0.0.0:* 2097/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 2097/dnsmasq
udp 0 0 0.0.0.0:68 0.0.0.0:* 6198/dhclient
udp 0 0 0.0.0.0:111 0.0.0.0:* 798/rpcbind
udp 0 0 127.0.0.1:323 0.0.0.0:* 818/chronyd
udp 0 0 0.0.0.0:972 0.0.0.0:* 798/rpcbind
udp 0 0 0.0.0.0:33872 0.0.0.0:* 809/avahi-daemon: r
udp 0 0 0.0.0.0:5353 0.0.0.0:* 809/avahi-daemon: r
udp6 0 0 :::111 :::* 798/rpcbind
udp6 0 0 ::1:323 :::* 818/chronyd
udp6 0 0 :::972 :::* 798/rpcbind
[root@Hadoop2 ~]#
运行后
[root@Hadoop2 ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 798/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6464/docker-proxy
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2097/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1211/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1209/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1403/master
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2144/sshd: root@pts
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 6197/sshd: root@pts
tcp6 0 0 :::111 :::* LISTEN 798/rpcbind
tcp6 0 0 :::80 :::* LISTEN 6471/docker-proxy
tcp6 0 0 :::22 :::* LISTEN 1211/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1209/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1403/master
tcp6 0 0 ::1:6010 :::* LISTEN 2144/sshd: root@pts
tcp6 0 0 ::1:6011 :::* LISTEN 6197/sshd: root@pts
udp 0 0 192.168.122.1:53 0.0.0.0:* 2097/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 2097/dnsmasq
udp 0 0 0.0.0.0:68 0.0.0.0:* 6198/dhclient
udp 0 0 0.0.0.0:111 0.0.0.0:* 798/rpcbind
udp 0 0 127.0.0.1:323 0.0.0.0:* 818/chronyd
udp 0 0 0.0.0.0:972 0.0.0.0:* 798/rpcbind
udp 0 0 0.0.0.0:33872 0.0.0.0:* 809/avahi-daemon: r
udp 0 0 0.0.0.0:5353 0.0.0.0:* 809/avahi-daemon: r
udp6 0 0 :::111 :::* 798/rpcbind
udp6 0 0 ::1:323 :::* 818/chronyd
udp6 0 0 :::972 :::* 798/rpcbind
[root@Hadoop2 ~]#