加载中...
加载中...
Docker入门教程
![image-20231104220956343](http://www.leixingke.com:80/img/2023/11/04/1699107539246606.png) 官方文档 https://www.docker.com/ https://docs.docker.com/ http://docker.p2hp.com/ Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的[镜像](https://baike.baidu.com/item/镜像/1574?fromModule=lemma_inlink)中,然后发布到任何流行的 Linux或[Windows](https://baike.baidu.com/item/Windows/165458?fromModule=lemma_inlink)操作系统的机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。 https://blog.csdn.net/qq_54729417/article/details/127913536 ## Docker安装 https://docs.docker.com/engine/install/centos/ ```linux # 系统内核 [root@luolei ~]# uname -r 3.10.0-957.21.3.el7.x86_64 # 查看系统版本 [root@luolei ~]# cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7" # 1.卸载旧的版本 yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine # 2.需要的安装包 yum install -y yum-utils # 3.设置镜像的仓库 yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo # 默认是从国外的。 yum-config-manager \ --add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # 推荐使用阿里云的。 # 安装容器之前,更新yum软件包索引。 yum makecache fast # 4.安装容器相关的。docker-ce(社区版)docker-ee(企业版) yum install docker-ce docker-ce-cli containerd.io # 5.启动docker systemctl start docker # 6.使用docker version查看是否安装成功 docker version # 7.测试hello-world docker run hello-world # 1.卸载依赖 yum remove docker-ce docker-ce-cli containerd.io # 2.删除资源 rm -rf /var/lib/docker rm -rf /var/lib/containerd # /var/lib/docker docker的默认工作路径 ``` ## Docker 镜像 ```linux docker images [root@luolei ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 9c7a54a9a43c 6 months ago 13.3kB -a, --all # 显示所有镜像 (docker images -a) -q, --quiet # 仅显示镜像id (docker images -q) docker 命令 --help # 帮助命令 docker search(搜索镜像) docker search mysql docker search mysql --filter=STARS=4000 [root@luolei ~]# docker search mysql --filter=STARS=3000 NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 14574 [OK] mariadb MariaDB Server is a high performing open sou… 5561 [OK] docker pull(下载镜像) [root@luolei ~]# docker pull mysql:5.7 docker rmi(删除镜像) [root@luolei ~]# docker rmi -f 镜像id # 删除指定的镜像 [root@luolei ~]# docker rmi -f 镜像id 镜像id 镜像id # 删除多个镜像(空格分隔) [root@luolei ~]# docker rmi -f $(docker images -aq) # 删除全部的镜像 [root@luolei ~]# docker rmi -f $(docker images -aq) Untagged: hello-world:latest Untagged: hello-world@sha256:88ec0acaa3ec199d3b7eaf73588f4518c25f9d34f58ce9a0df68429c5af48e8d Deleted: sha256:9c7a54a9a43cca047013b82af109fe963fde787f63f9e016fdc3384500c2823d ``` ## Docker 容器 ```linux 有了镜像才可以创建容器,linux,下载一个centos 镜像 [root@luolei ~]# docker pull centos docker run [可选参数] image # 参数说明 --name="name" 容器名字:用来区分容器 -d 后台方式运行:相当于nohup -it 使用交互式运行:进入容器查看内容 -p 指定容器的端口(四种方式)小写字母p -p ip:主机端口:容器端口 -p 主机端口:容器端口 -p 容器端口 容器端口 -P 随机指定端口(大写字母P) # 测试:启动并进入容器 [root@luolei ~]# docker run -it centos /bin/bash [root@f8fad61a6c96 /]# ls # 查看容器内的centos(基础版本,很多命令都是不完善的) # 从容器中退回到主机 [root@fdffdfd /]# exit exit 列出所有运行的容器 [root@luolei ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 删除容器 docker rm 容器id # 删除容器(不能删除正在运行的容器)如果要强制删除:docker rm -f 容器id docker rm -f $(docker ps -aq) # 删除全部容器 docker ps -a -q|xargs docker rm # 删除所有容器 启动和停止容器的操作 docker start 容器id # 启动容器 docker restart 容器id # 重启容器 docker stop 容器id # 停止当前正在运行的容器 docker kill 容器id # 强制停止当前容器 ```
没有更多推荐了 [去首页]
image
文章
376
原创
293
转载
83
翻译
0
访问量
183398
喜欢
73
粉丝
5
码龄
7年
资源
3

文章目录

加载中...
0
0