获取docker镜像
docker镜像使用
docker可以让我们部署项目更快,迁移更简单。
开发机器:windows,又不想搞乱当前机器的环境,使用docker来解决。
使用流程:
1、下载安装docker工具
2、获取该软件的docker镜像(以后需要使用的各种工具,基本上都能够搜索到合适的镜像去用)
如:nginx镜像 docker pull nginx
3、运行该镜像,然后就启动了一个容器,这个nginx服务就运行在容器中
4、停止容器,删除该镜像。
基于镜像的增删改查维护
获取镜像
获取镜像,镜像中托管仓库中。默认的docker仓库是dockerhub,有大量的优质镜像,以及用户自己上传的镜像。
命令:docker search 镜像名:tag tag就是具体的标签版本
从dockerhub获取镜像流程:
查看docker应用程序是否启动:
命令:docker version
如下图说明已经启动:
[root@localhost ~]# docker verison docker: 'verison' is not a docker command. See 'docker --help' [root@localhost ~]# docker version Client: Docker Engine - Community Version: 20.10.7 API version: 1.41 Go version: go1.13.15 Git commit: f0df350 Built: Wed Jun 2 11:58:10 2021 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.6 API version: 1.41 (minimum version 1.12) Go version: go1.13.15 Git commit: 8728dd2 Built: Fri Apr 9 22:43:57 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4.8 GitCommit: 7eba5930496d9bbe375fdf71603e610ad737d2b2 runc: Version: 1.0.0 GitCommit: v1.0.0-0-g84113ee docker-init: Version: 0.19.0 GitCommit: de40ad0
查看当前有没有容器在运行中
命令:docker ps
如图nginx在容器中运行
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3bfef5025609 nginx "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp, :::80->80/tcp keen_wing
查看本地镜像文件有哪些
命令:docker images 或 docker images ls
下载docker 镜像
命令1下载最新的镜像: docker pull 镜像名
命令2下载指定版本镜像:docker pull 镜像名:版本号
查看docker镜像的存储路径
查看docker信息:docker info
[root@localhost ~]# docker info Client: Context: default Debug Mode: false Plugins: app: Docker App (Docker Inc., v0.9.1-beta3) buildx: Build with BuildKit (Docker Inc., v0.5.1-docker) scan: Docker Scan (Docker Inc., v0.8.0) Server: Containers: 6 Running: 1 Paused: 0 Stopped: 5 Images: 5 Server Version: 20.10.6 Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 1 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc Default Runtime: runc Init Binary: docker-init containerd version: 7eba5930496d9bbe375fdf71603e610ad737d2b2 runc version: v1.0.0-0-g84113ee init version: de40ad0 Security Options: seccomp Profile: default Kernel Version: 3.10.0-1160.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 3.682GiB Name: localhost.localdomain ID: NZ2I:JHCL:QBPJ:LWSM:ZNF5:UCIH:7NKG:LROY:YPEU:2ACZ:W7IF:AN3H Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://8xpk5wnt.mirror.aliyuncs.com/ Live Restore Enabled: false
查看docker所有数据存放目录:docker info |grep Root
[root@localhost ~]# docker info |grep Root Docker Root Dir: /var/lib/docker
docker数据存放目录
[root@localhost ~]# ls /var/lib/docker buildkit containers image network overlay2 plugins runtimes swarm tmp trust volumes
docker镜像存储目录:ls /var/lib/docker/image/overlay2/imagedb/content/sha256
使用不同的镜像生成容器
--it 开启一个交互式的终端
--rm 容器退出时删除容器
运行容器centos
[root@localhost ~]# docker run -it --rm centos bash
查看运行发行版
[root@36dd3c436b4e /]# cat /etc/redhat-release
CentOS Linux release 8.3.2011
退出容器命令:exit
运行指定版本容器命令:docker run -it --rm centos:版本号 bash