Docker应用

mac Docker基本操作命令

2021-05-14  本文已影响0人  Geroge1226

docker中央仓库: index.docker.io 可以自己搭建私域仓库。

1、docker Images 查看docker 本地镜像

[lsy@lsyPro /etc ]$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
rabbitmq     latest    32497bcd639d   3 days ago   156MB

REPOSITORY: 仓库中镜像名称
TAG: 镜像的标签信息,比如 5.7、latest 表示不同的版本信息;
IMAGE ID:镜像的 ID, 如果您看到两个 ID 完全相同,那么实际上,它们指向的是同一个镜像,只是标签名称不同罢了;
CREATED:镜像最后的更新时间;
SIZE: 镜像的大小,优秀的镜像一般体积都比较小,这也是我更倾向于使用轻量级的 alpine 版本的原因;

2、docker pull 拉取镜像

[lxx@lsyPro /etc ]$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
69692152171a: Pull complete 
49f7d34d62c1: Pull complete 
5f97dc5d71ab: Pull complete 
cfcd0711b93a: Pull complete 
be6172d7651b: Pull complete 
de9813870342: Pull complete 
Digest: sha256:df13abe416e37eb3db4722840dd479b00ba193ac6606e7902331dcea50f4f1f2
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

说明
1、pull的镜像名称均为小写,可以在中央仓库中搜索到
2、 指定版本号

3、docker ps 查看docker中运行的容器

[lxxd@lsyPro /etc ]$ docker ps 
CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS          PORTS                                                                                              NAMES
b1926a54a2e3   rabbitmq   "docker-entrypoint.s…"   25 seconds ago   Up 23 seconds   4369/tcp, 0.0.0.0:5672->5672/tcp, 5671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp   rbmq

4、docker run 启动容器

[lng@lsyPro /etc ]$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:5122f6204b6a3596e048758cabba3c46b1c937a46b5be6225b835d091b90e46c
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/

4.1 说明:

4.2 参数说明

参数 全称 说明
-d --detached==false 指定容器运行于前台还是后台,默认为false( in background)
-h --hostname="" 指定容器的主机名
--name --name="" 指定容器名字,后续可以通过名字进行容器管理,links特性需要使用名字
-p --publish=[] (小写p)指定容器暴露的端口

【例子】

docker run -d --hostname my-rabbit --name rabbit -p 15672:15672 -p 5672:5672 rabbitmq
上一篇 下一篇

猜你喜欢

热点阅读