1、 安装docker-ce并执行以下命令
docker --version
docker version
docker run hello-world
docker run -it ubuntu bash
[root@zzz ~]# docker version #用于显示docker的版本信息,包括docker client 和docker server
Client: Docker Engine - Community
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:05:12 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@zzz ~]#
[root@zzz ~]# docker --version #显示docker的版本
Docker version 20.10.17, build 100c701
命令格式:
docker run [OPTIONS] IMAGE [COMMAND] [ARG…]
常用OPTIONS:
-t:打开一个终端,像使用交换机一样使用容器
-i:交互式访问
—name:容器名字
—network:指定网络
—rm:容器一停,自动删除
-d:后台运行容器,返回容器ID;否则会一直占据着终端
-p:端口映射,将容器内服务的端口映射在宿主机的指定端口,格式为:主机(宿主)端口:容器端口
-P: 随机端口映射,容器内部端口随机映射到主机的端口
[root@zzz ~]# docker run hello-world #启动容器(从仓库拉取)用来检测docker是否安装成功
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/
[root@zzz ~]# docker run -it ubuntu bash #运行容器并交互式进入容器
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Downloaded newer image for ubuntu:latest
root@d41bcc87ab2d:/# ls
bin boot dev etc home lib lib32 lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr var
root@d41bcc87ab2d:/# exit
exit
[root@zzz ~]#
2、下载并查看镜像
下载nginx的镜像,alpine的镜像,httpd的镜像并且给httpd镜像重新打标签为test/httpd:v1
拉取镜像
docker pull[选项][Docker Registry 地址[:端口号]/]仓库名[:标签]
[root@zzz ~]# docker pull nginx:latest #拉取nginx镜像,版本:最新
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@zzz ~]# docker pull alpine #拉取alpine镜像,不注明版本默认最新
Using default tag: latest
latest: Pulling from library/alpine
59bf1c3509f3: Pull complete
Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
[root@zzz ~]# docker pull httpd #拉取httpd镜像,不注明版本默认最新
Using default tag: latest
latest: Pulling from library/httpd
a2abf6c4d29d: Already exists
dcc4698797c8: Pull complete
41c22baa66ec: Pull complete
67283bbdd4a0: Pull complete
d982c879c57e: Pull complete
Digest: sha256:0954cc1af252d824860b2c5dc0a10720af2b7a3d3435581ca788dff8480c7b32
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
[root@zzz ~]# docker tag httpd test/httpd:v1
[root@zzz ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 7 months ago 141MB
httpd latest dabbfbe0c57b 8 months ago 144MB
test/httpd v1 dabbfbe0c57b 8 months ago 144MB
alpine latest c059bfaa849c 8 months ago 5.59MB
ubuntu latest ba6acccedd29 10 months ago 72.8MB
hello-world latest feb5d9fea6a5 10 months ago 13.3kB