docker之镜像下载


1、镜像搜索

[root@localhost ~]# docker search nginx 
NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx.
16057 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 2105 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 819 [OK] jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 303 linuxserver/nginx An Nginx container, brought to you by LinuxS… 161 jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 148 [OK] tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 148 [OK] alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 112 [OK] nginxdemos/hello NGINX webserver that serves a simple page co… 81 [OK] privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 61 [OK] docker镜像名字           描述                 受欢迎程度   是否官方提供

2、镜像下载

方法1:从docker hub 拉取

[root@localhost ~]#  docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

方法2:使用阿里云加速器

 https://cr.console.aliyun.com(需要注册)

 配置加速器 


[root@localhost ~]# mkdir -p /etc/docker  #
[root@localhost ~]# tee /etc/docker/daemon.json <<-'EOF' 
{
  "registry-mirrors": ["加速地址"]
}
EOF
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

查看配置情况(红色部分为你的加速地

[root@localhost ~]# docker info...
 Registry Mirrors:
  https://xxxxxx.mirror.aliyuncs.com/
 Live Restore Enabled: false

方法3:image镜像导入

[root@localhost ~]# docker load -i /root/docker-nginx.tar

方法4:直接下载其他站点的镜像

[root@localhost ~]# docker pull hub.c.163.com/library/nginx:latest
latest: Pulling from library/nginx
5de4b4d551f8: Pull complete 
d4b36a5e9443: Pull complete 
0af1f0713557: Pull complete 
Digest: sha256:f84932f738583e0169f94af9b2d5201be2dbacc1578de73b09a6dfaaa07801d6
Status: Downloaded newer image for hub.c.163.com/library/nginx:latest
hub.c.163.com/library/nginx:latest

3、查看 images 列表

 

[root@localhost ~]#  docker images
REPOSITORY                                                        TAG        IMAGE ID       CREATED         SIZE
nginx                                                             latest     605c77e624dd   3 days ago      141M

docker ps // 查看所有正在运行容器
docker stop containerId // containerId 是容器的ID

docker ps -a // 查看所有容器
docker ps -a -q // 查看所有容器ID

docker stop $(docker ps -a -q) //  stop停止所有容器
docker  rm $(docker ps -a -q) //   remove删除所有容器
 

4、开启动网络转发功能

[root@localhost ~]#  vim /etc/sysctl.conf  #插入以下内容
net.ipv4.ip_forward = 1[root@localhost ~]# sysctl  -p   #生效
net.ipv4.ip_forward = 1[root@localhost ~]#  cat /proc/sys/net/ipv4/ip_forward
1
否则,docker启动实例时,会报错以下警告:
[root@localhost ~]# systemctl stop firewalld && systemctl disable firewalld #关闭防火墙

5、启动实列nginx

[root@localhost ~]# docker run --name nginx -p 80:80 -d nginx
f47856b2612acd70f938b373d0f37b956232018b691d302b18ef982014a60918

需要手动创建daemon.json文件