# 启动Docker
systemctl start docker
# 测试Docker
docker run hello-world
[root@salve-1 /]# systemctl start docker[root@salve-1 /]# docker run hello-world
Unable to find image 'hello-world:latest' locally # 没有找到镜像
latest: Pulling from library/hello-world # 去官方库拉取
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
# 此消息显示您的安装似乎正在正常工作。
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
# 查看版本号
docker version
# 查看镜像[root@salve-1 /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 4 months ago 13.3kB
docker version # 显示版本号
docker info # 显示docker的系统信息
docker 命令 --help # 查看命令的帮助信息(命令代表所有docker命令)
镜像命令
查看所有镜像
[root@salve-1 docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 4 months ago 13.3kB
REPOSITORY # 镜像的仓库源
TAG # 镜像的标签
IMAGE ID # 镜像的ID
CREATED # 创建日期
SIZE # 大小# 可选参数
Options:
-a, --all Show all images (default hides intermediate images)
--digests Show digests
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print images using a Go template
--no-trunc Don't truncate output
-q, --quiet Only show image IDs
搜索镜像
[root@salve-1 docker]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11164 [OK]
mariadb MariaDB Server is a high performing open sou… 4235 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 830 [OK
# 可选参数
Options:
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print search using a Go template
--limit int Max number of search results (default 25)
--no-trunc Don't truncate output
[root@salve-1 docker]# docker search mysql --filter=STARS=3000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11164 [OK]
mariadb MariaDB Server is a high performing open sou… 4235 [OK]
下载镜像
[root@salve-1 docker]# docker pull mysql
Using default tag: latest # 默认下载的是最新版
latest: Pulling from library/mysql
latest: Pulling from library/mysql
33847f680f63: Pull complete # 从这里开始,就分层下载,这是docker的核心,联合文件下载
5cb67864e624: Pull complete
1a2b594783f5: Pull complete
b30e406dd925: Pull complete
48901e306e4c: Pull complete
603d2b7147fd: Pull complete
802aa684c1c4: Pull complete
715d3c143a06: Pull complete
6978e1b7a511: Pull complete
f0d78b0ac1be: Pull complete
35a94d251ed1: Pull complete
36f75719b1a9: Pull complete
Digest: sha256:8b928a5117cf5c2238c7a09cd28c2e801ac98f91c3f8203a8938ae51f14700fd # 签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest # 真实的地址# 以下两个命令是等价的
docker pull mysql
docker pull docker.io/library/mysql:latest
# 也可以指定版本下载,但是版本号必须是真是存在的才行[root@salve-1 docker]# docker pull mysql:5.7
5.7: Pulling from library/mysql
33847f680f63: Already exists
5cb67864e624: Already exists
1a2b594783f5: Already exists
b30e406dd925: Already exists
48901e306e4c: Already exists
603d2b7147fd: Already exists
802aa684c1c4: Already exists
5b5a19178915: Pull complete
f9ce7411c6e4: Pull complete
f51f6977d9b2: Pull complete
aeb6b16ce012: Pull complete
Digest: sha256:be70d18aedc37927293e7947c8de41ae6490ecd4c79df1db40d1b5b5af7d9596
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
# 查看上面下载的两个镜像[root@salve-1 docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 8cf625070931 2 days ago 448MB
mysql latest c60d96bd2b77 2 days ago 514MB
hello-world latest d1165f221234 4 months ago 13.3kB