下载前查看一下自己的电脑芯片是英特尔还是苹果芯片,内存要在4GB以上,下载官网:https://www.docker.com/get-started/
下载得到dmg文件后的操作和安装普通软件的操作是一样的,根据提示进行就可以,最后安装完成。
配置docker可使用的资源环境
docker version #查看版本信息
docker info #系统信息
docker [命令] --help
# fariy @ bogon in ~ [16:48:52] C:68
$ docker version
Client:
Cloud integration: v1.0.23
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:49:20 2022
OS/Arch: darwin/amd64
Context: default
Experimental: true
Server: Docker Desktop 4.7.1 (77678)
Engine:
Version: 20.10.14
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 87a90dc
Built: Thu Mar 24 01:46:14 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.11
GitCommit: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
# fariy @ bogon in ~ [16:48:52] C:68
$ docker version
Client:
Cloud integration: v1.0.23
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:49:20 2022
OS/Arch: darwin/amd64
Context: default
Experimental: true
Server: Docker Desktop 4.7.1 (77678)
……
# fariy @ bogon in ~ [16:59:37]
$ docker info --help
Usage: docker info [OPTIONS]
Display system-wide information
Options:
-f, --format string Format the output using the given Go template
docker images -a #显示所有的镜像
docker images -q #只显示镜像的ID
# fariy @ bogon in ~ [17:01:09]
$ docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest fa5269854a5e 2 weeks ago 142MB
centos latest 5d0da3dc9764 7 months ago 231MB
# fariy @ bogon in ~ [17:04:07]
$ docker images -q
fa5269854a5e
5d0da3dc9764
搜索镜像
docker search mysql
docker search mysql --filter=stars=3000 #筛选出收藏量大于3000的版本
# fariy @ bogon in ~ [17:08:09]
$ docker search mysql --filter=stars=3000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 12521 [OK]
mariadb MariaDB Server is a high performing open sou… 4816 [OK]
上述操作等价于直接从dockerhub搜索,点击MySQL后页面中有MySQL的现存型号
下载镜像
docker pull mysql #下载最新的版本
docker pull mysql:5.7 #下载指定的版本(版本需要从dockerhub网站查找)
删除镜像
docker rmi -f imageid
docker rmi -f imageid1 imageid2
docker rmi -f $(docker images -aq) #删除所有的镜像
# fariy @ bogon in ~ [16:47:39]
$ docker rmi -f ebad34c695d3
Untagged: nginx:1.20.2
Untagged: nginx@sha256:7dfea820d4c89037c6475c36567fcd439d54fe3810f459cbf580061c659b0dd6
Deleted: sha256:ebad34c695d3e5d265b583efdb9a58654c63adaa35c1410d67be6ad738b9d8e2
Deleted: sha256:a8b456f93cf2d57a83386498b570aafca3ed21eed9dccc2cccb655b7ee66a296
Deleted: sha256:0bf042184fe3d0286b4225d6febe82be45f475cc18f9153660b6b9d98671e501
Deleted: sha256:bf5bf60a9e4f17b6eeb9c8d95e712d468c81bfb48f2b0cffaaeb66726764b59e
Deleted: sha256:4d9a8da06966253ef5ae74803de6feaccf26d52441f0b4a3b875b776ff2b7afe
Deleted: sha256:80f35e70bd140c63f5774223d3e9f31356a0b2afc838cd615b0a1b9f8f65fb87
启动容器
docker run [参数] image仓库
#参数说明
–name=“name”
-d 后台运行
-it 交互式运行
-p 指定容器端口
-P 随机指定容器端口
列出容器
docker ps [参数]
#参数说明
-a 正在运行且历史运行过的容器
-q 只显示容器编号
# fariy @ bogon in ~ [17:36:43]
$ docker ps -aq
30ab1c6e8553
97d2a37445dd
6af7cfbe88f8
9897cfe3f348
ce1f1f6f1540
6deb26e2ea2a
a41b3c5f4c27
48c036c11524
删除容器
docker rm containerID #无法删除正在运行的容器
docker rm -f containerID
docker rm -f $(docker ps -aq) #删除所有的容器
启动or停止容器
docker start containerID
docker restart containerID
docker stop containerID
docker kill containerID #强制停止
docker top containerID #查看容器进程
docker inspect containerID #查看容器的原数据
docker exec -it containerID /bin/bash #开启新的终端,可以在里面操作
docker attach containerID #进入正在运行的容器
docker cp containerID 被复制文件的容器地址 主机地址