容器——docker

目录

1.安装docker服务,配置镜像加速器

[2.下载系统镜像(Ubuntu、 centos)](#2.下载系统镜像(Ubuntu、 centos))

[3.基于下载的镜像创建两个容器 (容器名一个为自己名字全拼,一个为首名字字母)](#3.基于下载的镜像创建两个容器 (容器名一个为自己名字全拼,一个为首名字字母))

[4.容器的启动、 停止及重启操作](#4.容器的启动、 停止及重启操作)

5.怎么查看正在运行的容器和所有容器?

[6.怎么退出容器: 两种方法分别实现?](#6.怎么退出容器: 两种方法分别实现?)

7.怎么连接到运行的容器?

8.查看容器或镜像的内部信息?

9.如何查看所有镜像?


1.安装docker服务,配置镜像加速器

1)、环境

复制代码
#服务器版本
[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

#内核版本
[root@localhost ~]# uname -r
3.10.0-1160.el7.x86_64

2)、添加并修改docker-ce源信息00

复制代码
[root@localhost ~]# yum install yum-utils device-mapper-persistent-data lvm2 -y

[root@localhost ~]# sed -i 's@download.docker.com@mirrors.tuna.tsinghua.edu.cn/docker-ce@g' /etc/yum.repos.d/docker-ce.repo

3)、更新并安装docker-CE

复制代码
[root@localhost ~]# yum makecache fast
[root@localhost ~]# yum -y install docker-ce

4)、配置docker镜像加速

复制代码
[root@localhost ~]# vim /etc/docker/daemon.json

{
"registry-mirrors":["http://hd1esep4.mirror.aliyuncs.com"]
}

[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl restart docker

5)、查看docker版本

root@localhost \~\]# docker version Client: Docker Engine - Community Version: 24.0.5 API version: 1.43 Go version: go1.20.6 Git commit: ced0996 Built: Fri Jul 21 20:39:02 2023 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 24.0.5 API version: 1.43 (minimum version 1.12) Go version: go1.20.6 Git commit: a61e2b4 Built: Fri Jul 21 20:38:05 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.22 GitCommit: 8165feabfdfe38c65b599c4993d227328c231fca runc: Version: 1.1.8 GitCommit: v1.1.8-0-g82f18fe docker-init: Version: 0.19.0 GitCommit: de40ad0

2.下载系统镜像(Ubuntu、 centos)

root@localhost \~\]# docker pull centos:7 7: Pulling from library/centos 2d473b07cdd5: Pull complete Digest: sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987 Status: Downloaded newer image for centos:7 docker.io/library/centos:7 \[root@localhost \~\]# docker pull ubuntu Using default tag: latest latest: Pulling from library/ubuntu 7b1a6ab2e44d: Pull complete Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 Status: Downloaded newer image for ubuntu:latest docker.io/library/ubuntu:latest

3.基于下载的镜像创建两个容器 (容器名一个为自己名字全拼,一个为首名字字母)

root@localhost \~\]# docker run --name wp -it ubuntu root@987276383c38:/# exit exit \[root@localhost \~\]# docker run --name wangp -it centos:7 \[root@8223d6f2e3e7 /\]# exit exit

4.容器的启动、 停止及重启操作

复制代码
#启动命令
[root@localhost ~]# docker start wp
wp

#停止命令
[root@localhost ~]# docker stop wp
wp

#重启命令
[root@localhost ~]# docker restart wp
wp

5.怎么查看正在运行的容器和所有容器?

复制代码
#查看正在运行的容器
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS          PORTS     NAMES
987276383c38   ubuntu    "bash"    2 minutes ago   Up 53 seconds             wp

#查看所有容器
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE      COMMAND       CREATED         STATUS                     PORTS     NAMES
8223d6f2e3e7   centos:7   "/bin/bash"   2 minutes ago   Exited (0) 2 minutes ago             wangp
987276383c38   ubuntu     "bash"        3 minutes ago   Up About a minute                    wp

6.怎么退出容器: 两种方法分别实现?

1)、[root@localhost ~]# docker run --name wp -it ubuntu /bin/bash

root@08f0ad338d35:/# exit

exit

2)、ctrl(长按)+p+q

7.怎么连接到运行的容器?

root@localhost \~\]# docker exec -it wangp /bin/bash \[root@8b8d60576bac /\]#

8.查看容器或镜像的内部信息?

复制代码
[root@localhost ~]# docker inspect wangp 

9.如何查看所有镜像?

root@localhost \~\]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest ba6acccedd29 22 months ago 72.8MB centos 7 eeb6ee3f44bd 23 months ago 204MB

相关推荐
万米商云1 分钟前
企业物资集采平台解决方案:跨地域、多仓库、百部门——大型企业如何用一套系统管好百万级物资?
大数据·运维·人工智能
i小溪9 分钟前
在使用 Docker 时,如果容器挂载的数据目录(如 `/var/moments`)位于数据盘,只要服务没有读写,数据盘是否就不会被唤醒?
人工智能·docker
挑战者66688833 分钟前
CentOS 系统高效部署 Dify 全攻略
linux·运维·centos
网硕互联的小客服2 小时前
服务器经常出现蓝屏是什么原因导致的?如何排查和修复?
运维·服务器·stm32·单片机·网络安全
喜欢吃豆2 小时前
从零构建MCP服务器:FastMCP实战指南
运维·服务器·人工智能·python·大模型·mcp
海外空间恒创科技2 小时前
恒创科技:香港站群服务器做seo站群优化效果如何
运维·服务器·科技
搬码临时工2 小时前
内网服务器怎么设置公网远程访问? windows桌面连接和Linux自带SSH外网异地跨网用完整步骤教程
运维·服务器·ssh
Rudon滨海渔村2 小时前
解决阿里云ubuntu内存溢出导致vps死机无法访问 - 永久性增加ubuntu的swap空间 - 阿里云Linux实例内存溢出(OOM)问题修复方案
linux·运维·ubuntu
苹果醋32 小时前
Vue3组合式API应用:状态共享与逻辑复用最佳实践
java·运维·spring boot·mysql·nginx
A-刘晨阳3 小时前
【Linux】Redis 6.2.6 的二进制部署【适用于多版本】
linux·运维·redis