Docker的安装与卸载、启动与停止

网友投稿 223 2022-10-17

Docker的安装与卸载、启动与停止

@toc

Docker的概述

Docker 是一个开源的应用容器引擎。 Docker 让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows 机器上,也可以实现虚拟化。 Docker 容器是完全使用沙箱机制,相互之间不会有任何接口。 Docker 从 17.03 版本之后分为 CE(Community Edition: 社区版) 和 EE(Enterprise Edition: 企业版)

三个重要概念

1.image镜像

docker镜像就是一个只读模板,比如,一个镜像可以包含一个完整的centos,里面仅安装apache或用户的其他应用,镜像可以用来创建docker容器,另外docker提供了一个很简单的机制来创建镜像或者更新现有的镜像,用户甚至可以直接从其他人那里下载一个已经做好的镜像来直接使用

2.container容器

docker利用容器来运行应用,容器是从镜像创建的运行实例,它可以被启动,开始、停止、删除、每个容器都是互相隔离的,保证安全的平台,可以把容器看做是简易版的linux环境(包括root用户权限、镜像空间、用户空间和网络空间等)和运行再其中的应用程序

3.repostory仓库

仓库是集中存储镜像文件的沧桑,registry是仓库主从服务器,实际上参考注册服务器上存放着多个仓库,每个仓库中又包含了多个镜像,每个镜像有不同的标签(tag) 仓库分为两种,公有参考,和私有仓库,最大的公开仓库是docker Hub,存放了数量庞大的镜像供用户下周,国内的docker pool,这里仓库的概念与Git类似,registry可以理解为github这样的托管服务 Docker的安装前提 Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。 Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。

Docker的安装

1.查看系统内核版本是否满足

执行命令:uname -r

[root@master ~]# uname -r 3.10.0-1062.4.1.e17.x86_64

2.确保 yum 包更新到最新。

yum update

3.安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

yum install -y yum-utils yum install -y device-mapper-persistent-data yum install -y lvm2 yum install -y yum-utils device-mapper-persistent-data lvm2

4.设置yum源为阿里云,提高下载速度,避免出现其他异常情况

yum-config-manager --add-repo list docker-ce --showduplicates | sort -r yum install # 例如: yum install docker-ce-3:19.03.9-3.el7

6.安装docker,默认最新稳定版

yum install docker-ce

7.安装后查看docker版本

执行命令:docker -v

[root@master ~]# docker -v Docker version 19.03.11,bu11d 42e35e61f3

8.设置国内镜像源,提高拉取docker镜像速度

登录阿里云控制台查看专属的镜像加速地址,并按照其提示进行修改

首先创建目录/etc/docker,然后执行命令:vi /etc/docker/daemon.json,输入配置内容。

[root@master ~]# mkdir /etc/docker [root@master ~]# touch /etc/docker/daemon.json [root@master ~]# vim /etc/docker/daemon.json

{ "registry-mirrors":[" }

常见的国内镜像源:

1. Docker中国区官方镜像 https://registry.docker-cn.com 2.网易 http://hub-mirror.c.163.com 3.ustc https://docker.mirrors.ustc.edu.cn 4.中国科技大学 https://docker.mirrors.ustc.edu.cn 5.阿里云容器 服务 daemon-reload systemctl restart docker

2、centOS7.0以下

service docker restart

Docker的卸载

查看docker状态:

systemctl status docker

[root@master ~]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2022-08-01 08:14:12 UTC; 11s ago Docs: https://docs.docker.com Main PID: 74220 (dockerd) Tasks: 8 Memory: 44.0M CGroup: /system.slice/docker.service └─74220 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

停止docker:

systemctl stop docker

查询安装docker的文件包

yum list installed | grep docker

删除所有安装docker的文件包

yum -y remove '包名'

删除卷/网络内容/镜像/容器等,默认在/var/lib/docker目录

rm -rf /var/lib/docker

[root@master ~]# ls /var/lib/docker buildkit containers image network overlay2 plugins runtimes swarm tmp trust volumes

Docker的启动与停止

Linux 服务管理两种方式service和systemctl systemd是Linux系统最新的初始化系统(init)命令

systemctl命令是系统服务管理器指令

启动docker:

systemctl start docker

查看docker状态:

systemctl status docker

停止docker:

systemctl stop docker

重启docker:

systemctl restart docker

开机启动:

systemctl enable docker

查看docker概要信息

docker info

[root@master ~]# docker info Client: Context: default Debug Mode: false Plugins: app: Docker App (Docker Inc., v0.9.1-beta3) buildx: Docker Buildx (Docker Inc., v0.8.2-docker) scan: Docker Scan (Docker Inc., v0.17.0) Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 20.10.17 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: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux Default Runtime: runc Init Binary: docker-init containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1 runc version: v1.1.2-0-ga916309 init version: de40ad0 Security Options: seccomp Profile: default Kernel Version: 4.18.0-372.16.1.el8_6.x86_64 Operating System: Red Hat Enterprise Linux 8.6 (Ootpa) OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 776.6MiB Name: master ID: 6RPI:GTBV:YHHB:3MSH:7UKS:UN46:5PMQ:EIQO:3C6T:GFG2:TDKV:QMEA 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://u6gcz43x.mirror.aliyuncs.com/ Live Restore Enabled: false

查看docker帮助文档

docker --help

[root@master ~]# docker --help Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: app* Docker App (Docker Inc., v0.9.1-beta3) builder Manage builds buildx* Docker Buildx (Docker Inc., v0.8.2-docker) config Manage Docker configs container Manage containers context Manage contexts image Manage images manifest Manage Docker image manifests and manifest lists network Manage networks node Manage Swarm nodes plugin Manage plugins scan* Docker Scan (Docker Inc., v0.17.0) secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumes Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command. To get more help with docker, check out our guides at https://docs.docker.com/go/guides/

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:在Java中实现二叉搜索树的全过程记录
下一篇:2 Tomcat部署
相关文章

 发表评论

暂时没有评论,来抢沙发吧~