Docker是一款针对程序开发人员和系统管理员来开发、部署、运行应用的一款虚拟化平台。Docker 可以让你像使用集装箱一样快速的组合成应用,并且可以像运输标准集装箱一样,尽可能的屏蔽代码层面的差异。Docker 会尽可能的缩短从代码测试到产品部署的时间。
docker可以安装运行在windows、linux、mac平台上,由于我这是mac系统,我就记录了一下在mac上安装docker.
下载地址: docker官网,找到对应的系统平台,下载docker,然后傻瓜式安装.
启动docker 点击小海豚进入docker界面,左下角是绿色的标识正在运行
检查docker是否安装成功,执行命令
docker info. # 查看docker的信息
docker -v. # 查看docker的版本
docker --help. # 查看docker的所有命令
docker 命令 --help # 查看指定命令的帮助信息
docker images # 查看本机所有的镜像
docker images
wangshuai@wangshuaideMacBook-Pro ~ % docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
python 3.6 2a09b9410ba8 2 weeks ago 902MB
docker/desktop-kubernetes kubernetes-v1.21.4-cni-v0.8.5-critools-v1.17.0-debian 5efbfa3e779a 6 weeks ago 299MB
tensorflow/tensorflow latest 94fc08a3795e 6 weeks ago 1.32GB
tensorflow/serving latest e874bf5e4700 4 months ago 406MB
列表参数介绍
REPOSITORY: 镜像的仓库源
TAG: 镜像的版本
IMAGE ID: 镜像的id
CREATED 镜像的启动时间
SIZE 镜像的大小
镜像的帮助命令信息
docker images --help
wangshuai@wangshuaideMacBook-Pro ~ % docker images --help
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all # 查看所有镜像
--digests Show digests
-f, --filter filter # 过滤镜像
--format string Pretty-print images using a Go template
--no-trunc Don't truncate output
-q, --quiet # 只显示镜像id
# 帮助文档可以帮助我们了解命令有哪些参数以及操作
# 提供一个docker images -q 查看所有镜像id给个案例,下面我们自己可以手动尝试一下
wangshuai@wangshuaideMacBook-Pro ~ % docker images -q
2a09b9410ba8
5efbfa3e779a
94fc08a3795e
e874bf5e4700
docker pull 镜像名称:版本 如果不加版本默认是latest最新的版本
# 命令 docker pull centos 下载一个centos镜像
wangshuai@wangshuaideMacBook-Pro ~ % docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
# 注意最后一行这里的 docker.io/library/centos:latest 就是我们的下载地址
docker pull centos 等价与
docker pull docker.io/library/centos:latest
docker search 镜像名称
# 命令: docker search mysql
wangshuai@wangshuaideMacBook-Pro ~ % docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11461 [OK]
mariadb MariaDB Server is a high performing open sou… 4351 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 848 [OK]
percona Percona Server is a fork of the MySQL relati… 555 [OK]
phpmyadmin phpMyAdmin - A web interface for MySQL and M… 332 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 91
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 88
centurylink/mysql Image containing mysql. Optimized to be link… 59 [OK]
databack/mysql-backup Back up mysql databases to... anywhere! 50
prom/mysqld-exporter 42 [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… 31
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 31 [OK]
mysql/mysql-router MySQL Router provides transparent routing be… 22
centos/mysql-56-centos7 MySQL 5.6 SQL database server 20
arey/mysql-client Run a MySQL client from a docker container 18 [OK]
fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas… 16 [OK]
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici… 3
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK]
jelastic/mysql An image of the MySQL database server mainta… 2
centos/mysql-80-centos7 MySQL 8.0 SQL database server 1
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 1 [OK]
monasca/mysql-init A minimal decoupled init container for mysql 0
# docker search 镜像名称就可以查到所有的镜像信息,当然这一定是镜像库中存在的,如果搜索一个根本不存在的镜像是肯定查不到的
# 我们搜索一个我自己乱写的镜像名称
wangshuai@wangshuaideMacBook-Pro ~ % docker search wang666666666
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker rmi -f 镜像id
# 命令 docker rmi -f 镜像id: 这里我们将刚才下载centos镜像删除掉
wangshuai@wangshuaideMacBook-Pro ~ % docker rmi -f 5d0da3dc9764
Untagged: centos:latest
Untagged: centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Deleted: sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6
Deleted: sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59
# docker rmi -f 镜像ID 删除指定一个镜像
# docker rmi -f 镜像ID 镜像ID 镜像ID 删除多个镜像
# docker rmi -f $(docker images -aq) 删除所有的镜像(未启动的镜像)
命令 docker ps 查看所有的容器
wangshuai@wangshuaideMacBook-Pro ~ % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
410bd2f960a0 tensorflow/serving "/usr/bin/tf_serving…" 6 seconds ago Up 5 seconds 8500-8501/tcp, 0.0.0.0:8888->8888/tcp, :::8888->8888/tcp sleepy_sanderson
容器参数
CONTAINER ID 容器ID
IMAGE 镜像名称
COMMAND 容器进程
CREATED 创建时间
STATUS 容器状态
PORTS 端口号
NAMES 容器名称
命令 docker ps -a 查看容器启动的历史记录
# 命令 docker ps -a
wangshuai@wangshuaideMacBook-Pro ~ % docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
410bd2f960a0 tensorflow/serving "/usr/bin/tf_serving…" 5 minutes ago Up 5 minutes 8500-8501/tcp, 0.0.0.0:8888->8888/tcp, :::8888->8888/tcp sleepy_sanderson
3cb88e24afdd 3c514de153d1 "java -jar /mes.jar" 39 hours ago Exited (143) 39 hours ago great_chaum
3cc943c0cc82 3c514de153d1 "java -jar /mes.jar" 39 hours ago Exited (130) 39 hours ago vigorous_morse
8138341515a7 3c514de153d1 "java -jar /mes.jar" 39 hours ago Created inspiring_cray
b5c8d394e163 3c514de153d1 "java -jar /mes.jar" 39 hours ago Exited (143) 4 hours ago mes-8090
8a445c9bc918 083d7564d904 "/docker-entrypoint.…" 40 hours ago Created
命令 docker run [可选参数] image:端口
#参数说明
–name=“名字” 指定容器名字
-d 后台方式运行
-it 使用交互方式运行,进入容器查看内容
-p 指定容器的端口
( -p ip:主机端口:容器端口 配置主机端口映射到容器端口
-p 主机端口:容器端口
-p 容器端口)
-P 随机指定端口(大写的P)
wangshuai@wangshuaideMacBook-Pro ~ % docker run -it -d -p 8501:8501 python:3.6 ./bin/bash
2ab4ac07be839fd6f76da47c91c27392552f1ab3e2c0982bcca172fa1b76f92d
# 启动成功后查看容器
wangshuai@wangshuaideMacBook-Pro ~ % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2ab4ac07be83 python:3.6 "./bin/bash" 33 seconds ago Up 32 seconds 0.0.0.0:8501->8501/tcp, :::8501->8501/tcp magical_khorana
83fc95c3671c python "./bin/bash" About a minute ago Up About a minute 0.0.0.0:8500->8500/tcp, :::8500->8500/tcp magical_ellis
410bd2f960a0 tensorflow/serving "/usr/bin/tf_serving…" 11 minutes ago Up 11 minutes 8500-8501/tcp, 0.0.0.0:8888->8888/tcp, :::8888->8888/tcp sleepy_sanderson
docker run -it [容器ID]
# exit (停止并推出容器)
# Ctrl+P+Q 不停止容器退出
# docker stop [容器ID]
wangshuai@wangshuaideMacBook-Pro ~ % docker stop 83fc95c3671c
83fc95c3671c
docker rm -f 容器ID #删除指定容器
docker rm -f $(docker ps -aq) #删除所有的容器
docker ps -a -q|xargs docker rm #删除所有的容器
wangshuai@wangshuaideMacBook-Pro ~ % docker rm -f 83fc95c3671c
83fc95c3671c
本文纯自学笔记,仅供学习参考,有错误的地方请指出, 后续还会继续学习docker的知识, 共勉