首页 > 其他分享 >docker之学习操作记录,跟我一起练

docker之学习操作记录,跟我一起练

时间:2025-01-06 13:35:12浏览次数:10  
标签:ago SYS 记录 4028GR 学习 kt docker TR2

我没有使用高权限,所以后边都要加sudo,你如果和我一起练习的话,注意一下。

1.查看状态

sudo systemctl status docker


2.查看镜像

kt@kt-SYS-4028GR-TR2:~$ sudo docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
kt@kt-SYS-4028GR-TR2:~$ sudo docker images --help

Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]

List images

Aliases:
  docker image ls, docker image list, docker images

Options:
  -a, --all             Show all images (default hides intermediate images)
      --digests         Show digests
  -f, --filter filter   Filter output based on conditions provided
      --format string   Format output using a custom template:
                        'table':            Print output in table format with column headers
                        (default)
                        'table TEMPLATE':   Print output in table format using the given Go
                        template
                        'json':             Print in JSON format
                        'TEMPLATE':         Print output using the given Go template.
                        Refer to https://docs.docker.com/go/formatting/ for more information
                        about formatting output with templates
      --no-trunc        Don't truncate output
  -q, --quiet           Only show image IDs
      --tree            List multi-platform images as a tree (EXPERIMENTAL)

3.search

kt@kt-SYS-4028GR-TR2:~$ sudo docker search mongo
NAME                 DESCRIPTION                                     STARS     OFFICIAL
mongo                MongoDB document databases provide high avai…   10469     [OK]
circleci/mongo       CircleCI images for MongoDB                     13        
litmuschaos/mongo                                                    1         
corpusops/mongo      https://github.com/corpusops/docker-images/     0         
uselagoon/mongo                                                      0         


 

kt@kt-SYS-4028GR-TR2:~$ docker search --help

Usage:  docker search [OPTIONS] TERM

Search Docker Hub for images

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
      --no-trunc        Don't truncate output

4.pull,最好指定版本,我认为的。注意系统的对应。打开

https://hub.docker.com/_/mongo/tags

docker pull mongo:latest

5删除 

docker rmi -f ID

6.运行

docker run 镜像名或ID
重要参数:
--name=''  容器名,自定义。
-d         后台。
-it        交互方式
-p         指定端口或映射
    主机:容器
    容器
-P         随机端口

测试:

kt@kt-SYS-4028GR-TR2:~$ sudo docker run -it contos /bin/bash
Unable to find image 'contos:latest' locally
docker: Error response from daemon: pull access denied for contos, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
kt@kt-SYS-4028GR-TR2:~$ sudo docker run -it centos /bin/bash
[root@5ba6a94f87fa /]# ls
bin  etc   lib	  lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@5ba6a94f87fa /]# exit
exit
kt@kt-SYS-4028GR-TR2:~$ 

7.查看 仓库

kt@kt-SYS-4028GR-TR2:~$ sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS                          PORTS     NAMES
103ec0f1f3cb   mongo     "docker-entrypoint.s…"   2 minutes ago    Exited (0) About a minute ago             stupefied_clarke
5ba6a94f87fa   centos    "/bin/bash"              4 minutes ago    Exited (0) 3 minutes ago                  pedantic_newton
326205a8bc00   5d0d      "/bin/bash"              11 minutes ago   Exited (0) 11 minutes ago                 goofy_pike
kt@kt-SYS-4028GR-TR2:~$ docker ps --help

Usage:  docker ps [OPTIONS]

List containers

Aliases:
  docker container ls, docker container list, docker container ps, docker ps

Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Format output using a custom template:
                        'table':            Print output in table format with column headers
                        (default)
                        'table TEMPLATE':   Print output in table format using the given Go
                        template
                        'json':             Print in JSON format
                        'TEMPLATE':         Print output using the given Go template.
                        Refer to https://docs.docker.com/go/formatting/ for more information
                        about formatting output with templates
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display container IDs
  -s, --size            Display total file sizes

8.容器操作

docker start  ID.

        restart ID.
        stop ID.
        kill ID.
kt@kt-SYS-4028GR-TR2:~$ sudo docker run -it centos /bin/bash
[root@5d0d29900adb /]# exit
exit
kt@kt-SYS-4028GR-TR2:~$ sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                      PORTS     NAMES
5d0d29900adb   centos    "/bin/bash"   14 seconds ago   Exited (0) 10 seconds ago             practical_galois
1f7192baecc2   centos    "/bin/bash"   4 minutes ago    Exited (0) 3 minutes ago              wonderful_poincare
1f97f4632d9f   centos    "/bin/bash"   6 minutes ago    Exited (0) 5 minutes ago              eloquent_shtern
kt@kt-SYS-4028GR-TR2:~$ sudo docker start 5d0d
5d0d
kt@kt-SYS-4028GR-TR2:~$ sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS                     PORTS     NAMES
5d0d29900adb   centos    "/bin/bash"   About a minute ago   Up 10 seconds                        practical_galois
1f7192baecc2   centos    "/bin/bash"   5 minutes ago        Exited (0) 4 minutes ago             wonderful_poincare
1f97f4632d9f   centos    "/bin/bash"   7 minutes ago        Exited (0) 6 minutes ago             eloquent_shtern
kt@kt-SYS-4028GR-TR2:~$ sudo docker stop 5dod
Error response from daemon: No such container: 5dod
kt@kt-SYS-4028GR-TR2:~$ sudo docker stop 5d0d
5d0d
kt@kt-SYS-4028GR-TR2:~$ sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS                     PORTS     NAMES
5d0d29900adb   centos    "/bin/bash"   About a minute ago   Exited (0) 3 seconds ago             practical_galois
1f7192baecc2   centos    "/bin/bash"   6 minutes ago        Exited (0) 5 minutes ago             wonderful_poincare
1f97f4632d9f   centos    "/bin/bash"   7 minutes ago        Exited (0) 7 minutes ago             eloquent_shtern
kt@kt-SYS-4028GR-TR2:~$ 

删除容器

docker rm ID

docker rm -f $(docker ps -aq)

9.其他操作:

kt@kt-SYS-4028GR-TR2:~$ sudo docker run -d centos
e31697546e141e3642cbdeeba977c3a789ffe5728a5ef5bf775f93a7ac74d1bf
kt@kt-SYS-4028GR-TR2:~$ sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS                     PORTS     NAMES
e31697546e14   centos    "/bin/bash"   9 seconds ago   Exited (0) 8 seconds ago             clever_feynman
5d0d29900adb   centos    "/bin/bash"   3 minutes ago   Exited (0) 2 minutes ago             practical_galois
1f7192baecc2   centos    "/bin/bash"   8 minutes ago   Exited (0) 7 minutes ago             wonderful_poincare
1f97f4632d9f   centos    "/bin/bash"   9 minutes ago   Exited (0) 9 minutes ago             eloquent_shtern
kt@kt-SYS-4028GR-TR2:~$ sudo docker restart e31
e31
kt@kt-SYS-4028GR-TR2:~$ sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                      PORTS     NAMES
e31697546e14   centos    "/bin/bash"   39 seconds ago   Exited (0) 2 seconds ago              clever_feynman
5d0d29900adb   centos    "/bin/bash"   4 minutes ago    Exited (0) 2 minutes ago              practical_galois
1f7192baecc2   centos    "/bin/bash"   8 minutes ago    Exited (0) 7 minutes ago              wonderful_poincare
1f97f4632d9f   centos    "/bin/bash"   10 minutes ago   Exited (0) 10 minutes ago             eloquent_shtern
kt@kt-SYS-4028GR-TR2:~$ 

容器在启动后,必须要有一个前台进程,如果没有,就自动退出。

如:nginx,如果没有提供服务就会退出。

10.查看容器的进程信息

docker top ID

 11.查看容器的信息

docker inspect ID

kt@kt-SYS-4028GR-TR2:~$ sudo docker top e31
Error response from daemon: container e31697546e141e3642cbdeeba977c3a789ffe5728a5ef5bf775f93a7ac74d1bf is not running
kt@kt-SYS-4028GR-TR2:~$ sudo docker inspect e31
[
    {
        "Id": "e31697546e141e3642cbdeeba977c3a789ffe5728a5ef5bf775f93a7ac74d1bf",
        "Created": "2025-01-06T01:49:41.490204538Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 0,
            "Error": "",
 

12.进入正在运行的容器

 方式一:进入后开启一个新的终端。

docker exec -it ID /bin/bash
 
kt@kt-SYS-4028GR-TR2:~$ sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                      PORTS     NAMES
e31697546e14   centos    "/bin/bash"   17 minutes ago   Exited (0) 17 minutes ago             clever_feynman
5d0d29900adb   centos    "/bin/bash"   21 minutes ago   Exited (0) 19 minutes ago             practical_galois
1f7192baecc2   centos    "/bin/bash"   25 minutes ago   Exited (0) 24 minutes ago             wonderful_poincare
1f97f4632d9f   centos    "/bin/bash"   27 minutes ago   Exited (0) 27 minutes ago             eloquent_shtern
kt@kt-SYS-4028GR-TR2:~$ sudo docker rm -f $(sudo docker ps -aq)
e31697546e14
5d0d29900adb
1f7192baecc2
1f97f4632d9f
kt@kt-SYS-4028GR-TR2:~$ sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
kt@kt-SYS-4028GR-TR2:~$ sudo docker run -it centos /bin/bash
[root@1320d092cdf4 /]# exit
exit
kt@kt-SYS-4028GR-TR2:~$ sudo docker restart 132
132
kt@kt-SYS-4028GR-TR2:~$ sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS         PORTS     NAMES
1320d092cdf4   centos    "/bin/bash"   37 seconds ago   Up 8 seconds             suspicious_swirles
kt@kt-SYS-4028GR-TR2:~$ sudo docker exec -it 132 /bin/bash
[root@1320d092cdf4 /]# ls
bin  etc   lib	  lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@1320d092cdf4 /]# 

方式2:使用前查看命令帮助。进入容器正在执行的。

docker attach  ID
kt@kt-SYS-4028GR-TR2:~$ sudo docker attach  132
[root@1320d092cdf4 /]# ls
bin  etc   lib	  lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@1320d092cdf4 /]# 

13.文件的cp.内外互考。注意。当前目录下,用.代替。别忘记了。

kt@kt-SYS-4028GR-TR2:~$ cd Desktop
kt@kt-SYS-4028GR-TR2:~/Desktop$ touch kt.txt
kt@kt-SYS-4028GR-TR2:~/Desktop$ ls
kt.txt  ls
kt@kt-SYS-4028GR-TR2:~/Desktop$ sudo docker cp kt.txt 132:/home
Successfully copied 1.54kB to 132:/home
kt@kt-SYS-4028GR-TR2:~/Desktop$ sudo docker attach 132
You cannot attach to a stopped container, start it first
kt@kt-SYS-4028GR-TR2:~/Desktop$ sudo docker attach 132
You cannot attach to a stopped container, start it first
kt@kt-SYS-4028GR-TR2:~/Desktop$ sudo docker ps 
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
kt@kt-SYS-4028GR-TR2:~/Desktop$ sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                     PORTS     NAMES
1320d092cdf4   centos    "/bin/bash"   17 minutes ago   Exited (0) 3 minutes ago             suspicious_swirles
kt@kt-SYS-4028GR-TR2:~/Desktop$ sudo docker restart 132
132
kt@kt-SYS-4028GR-TR2:~/Desktop$ sudo docker attach 132
[root@1320d092cdf4 /]# cd home
[root@1320d092cdf4 home]# ls
aa.txt	kt.txt
[root@1320d092cdf4 home]# exit
exit
kt@kt-SYS-4028GR-TR2:~/Desktop$ sudo docker cp 132:/home/aa.txt
"docker cp" requires exactly 2 arguments.
See 'docker cp --help'.

Usage:  docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
	docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

Copy files/folders between a container and the local filesystem
kt@kt-SYS-4028GR-TR2:~/Desktop$ sudo docker cp 132:/home/aa.txt .
Successfully copied 1.54kB to /home/kt/Desktop/.
kt@kt-SYS-4028GR-TR2:~/Desktop$ ls
aa.txt  kt.txt  ls
kt@kt-SYS-4028GR-TR2:~/Desktop$ 

标签:ago,SYS,记录,4028GR,学习,kt,docker,TR2
From: https://blog.csdn.net/weixin_42771529/article/details/144955018

相关文章

  • InvariantStock:利用不变特征学习掌握动态市场的投资策略优化
    “InvariantStock:LearningInvariantFeaturesforMasteringtheShiftingMarket”论文地址:https://arxiv.org/pdf/2409.00671Github地址:https://github.com/Haiyao-Nero/InvariantStock摘要在投资组合管理领域,准确预测股票收益是至关重要的,但传统方法通常未能有......
  • 用Portainer实现对Docker容器的管理(四)
    11.1.5PortainerContainers(容器)图11-8      如图11-8所示,Containerslist显示了Docker容器相关内容,您可以看到在本地已有的所有容器、它们的运行状态、不同容器日志、CPU和内存等资源利用情况、内部IP、端口的映射等。如果您对Docker命令比较熟悉的话,可以将其简单......
  • 【状态估计】【卡尔曼滤波kalman】UKF、EKF、粒子滤波PF学习与研究(Matlab代码实现)
    ......
  • docker部署最新6.2版Zabbix Server端.240103
    一、安装docker,参见本博客docker安装文档。二、启动空的mysql-eMYSQL_DATABASE="zabbix"\-eMYSQL_USER="zabbix"\-eMYSQL_PASSWORD="zabbix_pwd1234"\-eMYSQL_ROOT_PASSWORD="root_pwd12345"\-p3306:3......
  • 多智能体强化学习算法评估Hard模式来了!浙大、南栖仙策联手推出
    在人工智能领域,具有挑战性的模拟环境对于推动多智能体强化学习(MARL)领域的发展至关重要。在合作式多智能体强化学习环境中,大多数算法均通过星际争霸多智能体挑战(SMAC)作为实验环境来验证算法的收敛和样本利用率。然而随着MARL算法的不断进步,很多算法在SMAC环境上均表现出接近......
  • 如何系统学习 react 和 antd 技术
    系统学习React和AntDesign(antd)技术需要一个有条理的计划,涵盖基础知识、实践项目以及持续的学习和优化。以下是一个推荐的学习路径:1.学习基础JavaScript/ES6+:确保你对JavaScript语言本身有足够的理解,特别是ES6+的新特性,如箭头函数、解构赋值、模板字符串、类、模块......
  • 爬虫学习——27.JS逆向(3)
    RSA介绍RSA加密算法是一种非对称加密算法。在公开密钥加密和电子商业中RSA被广泛使用。有两把对应密钥,公钥和私钥。用公钥加密只能用私钥解开,用私钥加密只能用公钥解密。RSA加密解密网址:https://oktools.net/rsa公开密钥(publickey:公钥)私有密钥(privatekey:私钥)公......
  • docker部署RocketMQ.240108
    ​RocketMQ是阿里巴巴2016年MQ中间件,使用java语言开发,在阿里内部,RocketMQ承接了例如“双11”等高并发场景的消息流转,能够处理亿万级别的消息处理。RocketMQ各角色介绍Producer:消息的发送者Consumer:消息的接收者Broker:暂存和传输消息,如:邮局NameServer:管理Bro......
  • 【Docker应用】如何减少用于大型语言模型的 Docker 镜像大小
    掌握精简Docker镜像的技巧,以实现更快、更具成本效益的LLM部署。在生产环境中部署大型语言模型(LLMs)时,管理大型Docker镜像是一个常见的挑战。这些镜像由于庞大的模型权重和众多依赖项而变得臃肿,可能导致部署速度变慢、成本增加以及资源利用效率低下。减少Docker镜像大小不......
  • 关于java实现TLS socket的X509自签名证书的一次记录
    创建客户端和服务器端的证书文件通常涉及几个步骤,包括生成私钥、创建证书签名请求(CSR)、签发证书以及将这些信息打包到PKCS#12格式的文件中。以下是详细的步骤说明:1.安装OpenSSL首先,你需要安装OpenSSL,它是一个开源的SSL/TLS工具包,可以用来生成密钥对和证书。Windows:可以从......