引子
以后项目部署需要用到
Docker的一些基本概念
容器技术的核心概念有容器(container)、镜像(image)、仓库(registry)三个。
容器:具体的运行应用程序的一个进程,它里面包含应用程序的各种依赖。
镜像:创建容器的模板,根据不同配置的镜像来创建不同的容器使用。镜像和容器的关系可以理解为面向对象中类和实例对象的关系。
仓库:一个镜像只可以创建一种类型的容器,镜像多了就需要放到镜像仓库中存起来,仓库有本地镜像仓库和公共镜像仓库,平时使用本地仓库的镜像,没有的话去Registry hub公共镜像仓库下载。
Docker的一些基本操作
docker images — 查看所以镜像
[root@VM-4-3-centos ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql 5.7 09361feeb475 5 months ago 447MB hello-world latest d1165f221234 9 months ago 13.3kB kibana 7.6.2 f70986bc5191 20 months ago 1.01GB elasticsearch 7.6.2 f29a1ee41030 20 months ago 791MB nginx 1.10 0346349a1a64 4 years ago 182MB
docker search 镜像名 — 搜索相关镜像
[root@VM-4-3-centos ~]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 11803 [OK] mariadb MariaDB Server is a high performing open sou… 4492 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Create… 885 [OK] centos/mysql-57-centos7 MySQL 5.7 SQL database server 92 mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 89 centurylink/mysql Image containing mysql. Optimized to be link… 59 [OK] databack/mysql-backup Back up mysql databases to… anywhere! 54 prom/mysqld-exporter 44 [OK] deitch/mysql-backup REPLACED! Please use http://hub.docker.com/r… 41 [OK] tutum/mysql Base docker image to run a MySQL database se… 35 linuxserver/mysql A Mysql container, brought to you by LinuxSe… 34 schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 31 [OK] mysql/mysql-router MySQL Router provides transparent routing be… 23 centos/mysql-56-centos7 MySQL 5.6 SQL database server 21 arey/mysql-client Run a MySQL client from a docker container 19 [OK] fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas… 17 [OK] genschsa/mysql-employees MySQL Employee Sample Database 8 [OK] yloeffler/mysql-backup This image runs mysqldump to backup data usi… 7 [OK] openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6 idoall/mysql MySQL is a widely used, open-source relation… 3 [OK] ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 3 [OK] devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici… 3 jelastic/mysql An image of the MySQL database server mainta… 2 centos/mysql-80-centos7 MySQL 8.0 SQL database server 2 widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 1 [OK]
docker pull(-a) 镜像名:版本号 — 拉取镜像,-a pull all
docker push 192.168.0.100:5000/ubuntu — 推送镜像库到私有源
docker rmi(-f) 镜像名:版本号/镜像 ID — 删除镜像 (加上 -f 参数 强制删除)
docker rmi $(docker images -q) — 删除所有镜像
docker ps — 查看所以的容器
[root@VM-4-3-centos ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8b53b705f751 elasticsearch:7.6.2 “/usr/local/bin/dock…” 4 months ago Up 4 days 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch 695c4b8760d9 mysql:5.7 “docker-entrypoint.s…” 5 months ago Up 3 months 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
docker ps -a — 查看所有容器的状态
[root@VM-4-3-centos ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d4f6a7f1aa69 kibana:7.6.2 “/usr/local/bin/dumb…” 3 months ago Exited (0) 3 months ago kibana fa930b7a17c8 nginx:1.10 “nginx -g 'daemon of…” 4 months ago Exited (0) 3 months ago nginx 8b53b705f751 elasticsearch:7.6.2 “/usr/local/bin/dock…” 4 months ago Up 4 days 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch 695c4b8760d9 mysql:5.7 “docker-entrypoint.s…” 5 months ago Up 3 months 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql cdec81cc32a7 hello-world “/hello” 5 months ago Exited (0) 5 months ago compassionate_booth
docker exec -it 容器 name /bin/sh — 进入容器
exit — 退出容器
docker start/stop id/name[name…] — 启动/停止某个(多个)容器
docker kill name[name…] — 强制中断
docker restart name[name…] — 重启
docker pause name — 暂停
docker unpause name — 继续
docker rm name[name…] — 移除容器
docker rmi (-f) name[name…] — 移除镜像(-f:强制移除运行中容器)
简单的部署流程
第一步:连接远程镜像仓库 (docker login ip 地址:端口号) 第二步:获取远程仓库中的镜像 (docker push 镜像名) 第三步:获取仓库中所有镜像 (docker images ) 第四步:编写自己的 dockerfile 文件 第五步:build 当前镜像中的 dockerfile 文件,生成新的 dockerfile 文件。 (docker build -t 镜像名:tag . ) 第六步:本地测试是否 build 成功 【本步骤可省略】, (docker run -p 8081:80 -d --name 容器名 镜像名:tag) 第七步:查看当前运行的容器 (docker ps ) 第八步:测试成功后上传镜像, (docker push 镜像名:tag) 第九步:查看仓库中的所有镜像 (docker images)
其他
欢迎指正与指导!
|