docker 基础命令

本文详细介绍了Docker的基本操作,包括搜索镜像、下载镜像、查看镜像列表、创建并运行镜像、查看容器进程、启动和进入容器、查看容器地址、后台运行容器、获取容器日志、删除容器等步骤,是Docker新手入门的实用教程。
摘要由CSDN通过智能技术生成

一、搜索镜像

docker search nginx

二、下载镜像

docker image pull nginx:1.14-alpinedocker

三、查看镜像docker image ls

docker image ls

[root@localhost docker]# docker image ls
REPOSITORY   TAG           IMAGE ID       CREATED       SIZE
busybox      latest        16ea53ea7c65   2 weeks ago   1.24MB
nginx        1.14-alpine   8a2fb25a19f5   2 years ago   16MB

查看完整镜像id

docker image ls --no-trunc

[root@localhost docker]# docker image ls --no-trunc
REPOSITORY   TAG           IMAGE ID                                                                  CREATED       SIZE
busybox      latest        sha256:16ea53ea7c652456803632d67517b78a4f9075a10bfdc4fc6b7b4cbf2bc98497   2 weeks ago   1.24MB
nginx        1.14-alpine   sha256:8a2fb25a19f5dc1528b7a3fabe8b3145ff57fe10e4f1edac6c718a3cf4aa4b73   2 years ago   16MB

四、创建镜像,并且运行,如果本地没有镜像会自动下载,后运行

docker run --name b1 -it busybox:latest

ps: -it 是进入shell 交互

五、查看镜像进程

docker ps
docker container ls

查看未启动镜像进程

docker ps -a

[root@localhost docker]# docker container ls -a
CONTAINER ID   IMAGE            COMMAND   CREATED         STATUS                      PORTS     NAMES
02e092e1a95a   busybox:latest   "sh"      8 minutes ago   Exited (0) 20 seconds ago             b1

六、启动已创建镜像并进入镜像shell

docker container start -a -i b1

七、查看容器地址

docker inspect b1

八、镜像后台启动运行

docker run --name web1 -d nginx:1.14-alpine

[root@localhost docker]# docker run --name web1 -d nginx:1.14-alpine
24d12f6cba5c7218501e00225d0d2179b34ec67ffdf261ce501925a2e78a0cec

[root@localhost docker]# docker container ls 
CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS          PORTS     NAMES
24d12f6cba5c   nginx:1.14-alpine   "nginx -g 'daemon of…"   51 seconds ago   Up 50 seconds   80/tcp    web1

[root@localhost docker]# curl 172.17.0.2:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

九、进入后台运行容器进行交互

docker exec -it web1 /bin/sh

十、获取容器日志

docker container logs web1

[root@localhost docker]# docker container logs web1
172.17.0.1 - - [30/Sep/2021:09:18:06 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.61.1" "-"

十一、删除停止容器

docker container rm b1

[root@localhost docker]# docker container ls -a
CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS                      PORTS     NAMES
24d12f6cba5c   nginx:1.14-alpine   "nginx -g 'daemon of…"   22 minutes ago   Up 22 minutes               80/tcp    web1
02e092e1a95a   busybox:latest      "sh"                     36 minutes ago   Exited (0) 28 minutes ago             b1
[root@localhost docker]# docker container rm b1
b1
[root@localhost docker]# docker container ls -a
CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS          PORTS     NAMES
24d12f6cba5c   nginx:1.14-alpine   "nginx -g 'daemon of…"   22 minutes ago   Up 22 minutes   80/tcp    web1

docker 事件状态图

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值