ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

Dokcer(五) Dcoker的使用

Dokcer(五) Dcoker的使用 Docker安装Server版本以 OS版本Ubuntu 22.04 为例安装:cpu为x86_64:先卸载旧版本, 如果是新机器(云服务器or虚拟机)一般默认是没有的, 可以通过输入docker version查看, 如果没有这个命令, 就不需要卸载:如果需要卸载, 执行:# 1卸载旧版本sudoapt-getremovedockerdocker-engine docker.io containerd runc Reading package lists... Done Building dependency tree Reading state information... Done E: Unable tolocatepackage docker-engine# 2卸载历史版本# 卸载软件sudoapt-getpurge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras-y# 删除用户数据, 比如旧的容器,镜像等sudorm-rf/var/lib/dockersudorm-rf/var/lib/containerd配置 docker 下载源# 1. curl 命令安装sudoaptinstallcurl-y# 2. 添加 Docker 官方 GPG key:# 2.1 创建 gpg key 目录sudomkdir-m0755-p/etc/apt/keyrings# 2.2 下载 gpg keycurl-fsSLhttps://download.docker.com/linux/ubuntu/gpg|sudogpg--dearmor--yes-o/etc/apt/keyrings/docker.gpg添加 Docker 官方软件源# 3.1 添加 Docker 官方软件源echo\deb [arch$(dpkg --print-architecture)signed-by/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \$(lsb_release-cs)stable|sudotee/etc/apt/sources.list.d/docker.list/dev/null# 3.2 更新aptsudoapt-getupdate安装# 4. 安装sudoapt-getinstalldocker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin-y自动启动配置#配置加载sudosystemctl daemon-reload#启动服务sudosystemctl startdocker#开启启动sudosystemctlenabledocker查看服务状态sudo systemctl status docker, 可以看到docker服务正常启动6. 检查安装结果查看版本# docker版本, 可以看到客户端和服务端的版本以及组件dockerversion Client: Docker Engine - Community Version:29.8.1 API version:1.56Go version: go1.26.8 Git commit: 4a63305 Built: Tue Sep1516:25:262026OS/Arch: linux/amd64 Context: default....# 更详细查看 docker 信息dockerinfo 比如: Containers:0Running:0Paused:0Stopped:0Images:0Server Version:29.8.1 Storage Driver: overlayfs Docker Root Dir: /var/lib/docker配置Docker镜像源, 因为官网的docker hub 直连一般访问不了, 所以可以配置一些国内的镜像源,vim /etc/docker/daemon.json:{registry-mirrors:[https://镜像加速地址]}然后通过docker info, 可以看到server 配置的镜像源地址:Registry Mirrors: https://xx https://xxx运行一个helloworld试一下:sudodockerrun hello-world Unable tofindimagehello-world:latestlocally latest: Pulling from library/hello-world 4f55086f7dd0: Pull complete d5e71e642bf5: Download complete Digest: sha256:5e23090353324d887c48ad5e5c56d294eab81588df9605b07d1afe895f9cc8f8 Status: Downloaded newer imageforhello-world:latest Hello from Docker!This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled thehello-worldimage from the Docker Hub.(amd64)3. The Docker daemon created a new container from that imagewhichruns the executable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client,whichsent it to your terminal. To try somethingmoreambitious, you can run an Ubuntu container with: $dockerrun-itubuntubashShare images, automate workflows, andmorewith afreeDocker ID: https://hub.docker.com/ Formoreexamples and ideas, visit: https://docs.docker.com/get-started/Docker 目录修改Docker 默认的安装目录为/var/lib/docker,这里面会存放很多很多镜像所以我们在安装的时候需要考虑这个目录的空间有三种解决方案。1将/var/lib/docker 挂载到一个大的磁盘这种一般我们能控制挂载目录像腾讯云这种云厂商在安装 K8s 的节点的时候提供了挂载选项可以直接挂载这个目录过去2安装之前挂载一个大的磁盘然后创建一个软链接到/var/lib/docker这样就自动安装到我们空间比较大的磁盘了3安装了 docker然后发现忘了配置这个目录我们需要修改 docker 的配置文件# 假定我们磁盘的大的目录为 /datamkdir-p/data/var/lib/docker# 编辑配置文件vi/etc/docker/daemon.json添加data-root: “/data/var/lib/docker”:然后, 重新加载配置并重启docker:systemctl daemon-reload,systemctl restart docker.执行docker info后, 可以查看目录修改完毕:GUI 版本安装以Windows11为例:暂存
返回列表