Docker基本命令

  • 第一次使用docker,从helle world开始
  • docker run hello-world
  • 镜像的完整写法:[仓库地址/]镜像名[:版本号]

–help 查看帮助

  • 查看镜像
  • docker image ls 或 docker images
  • 查找镜像
  • docker search nginx
  • 拉取镜像
  • docker pull nginx
  • 查看镜像历史信息
  • docker image history nginx
  • 查看镜像详细信息
  • docker image inspect nginx
  • 删除无用镜像
  • docker image prune
  • 移除镜像
  • docker image rm nginx
  • docker rmi feb5d9fea6a5
  • 打包镜像
  • docker image save [OPTIONS] IMAGE [IMAGE…]
  • docker image save hello-world -o hello.tar
  • 加载镜像包
  • docker image load [OPTIONS]
  • docker image load -i “hello.tar”
  • 给镜像打标签
  • docker image tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
  • docker image tag hello-world:latest hello-world:1.0
  • 查看容器
  • docker ps 列出正常运行的容器
  • docker ps -a 参数-a列出所有的容器
  • 移除容器
  • docker rm 2276a5ecfaca
  • -f参数 强制删除
  • 运行容器
  • docker run nginx
  • docker run –name my_nginx nginx 运行一个名为my_nginx的nginx镜像
  • -it 交互 -d 后台运行 –rm 容器挂掉自动移除
docker exec --help

Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Run a command in a running container

Options:
  -d, --detach               Detached mode: run command in the background
      --detach-keys string   Override the key sequence for detaching a container
  -e, --env list             Set environment variables
      --env-file list        Read in a file of environment variables
  -i, --interactive          Keep STDIN open even if not attached
      --privileged           Give extended privileges to the command
  -t, --tty                  Allocate a pseudo-TTY
  -u, --user string          Username or UID (format: <name|uid>[:<group|gid>])
  -w, --workdir string       Working directory inside the container
</group|gid></name|uid>
  • 进入容器
  • docker exec -it nginxtest bash
  • nginxtest 容器名称或容器ID
  • exit 退出容器
docker commit --help

Usage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Create a new image from a container's changes

Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change list      Apply Dockerfile instruction to the created image
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)
</hannibal@a-team.com>
  • 通过容器生成一个新的镜像
  • docker commit -m ‘this is test’ mynginx my_nginx
docker push --help

Usage:  docker push [OPTIONS] NAME[:TAG]

Push an image or a repository to a registry

Options:
  -a, --all-tags                Push all tagged images in the repository
      --disable-content-trust   Skip image signing (default true)
  -q, --quiet                   Suppress verbose output

将镜像推送到远程仓库
  • 首先需要一个带仓库地址的镜像
  • docker commit -m ‘this is test’ mynginx repositoryname/my_nginx:1.0
  • 然后登录docker.hub账号
  • docker login
  • 最后就可以推送到自己的docker.hub远程仓库
  • docker image push repositoryname/my_nginx:1.0

端口映射

  • docker run –name my_nginx –rm -p 8080:80 nginx
  • -p 8080:80 端口映射 8080-宿主机端口 80-容器端端口 nginx-运行的镜像 –name 给容器起名 my_nginx 容器名称
  • 这样我们就可以在外部使用 ip+端口访问 容器my_nginx

数据卷挂载

  • docker run –name my_nginx –rm -d -v /root/test1:/root/test1 nginx
  • 将目录test1文件夹挂载到容器的test1文件夹下 这样即使容器被销毁了容器里的文件也会保存在我们的宿主机上
//&#x4F7F;&#x7528;exec&#x547D;&#x4EE4;&#x8FDB;&#x5165;&#x5BB9;&#x5668;
[root@iZuf620p8rsr3faul3zsx6Z ~]# docker exec -it my_nginx  bash
root@a87e160ee875:/# ls
bin   dev          docker-entrypoint.sh  home  lib64  mnt  proc  run   srv  tmp  var
boot  docker-entrypoint.d  etc           lib   media  opt  root  sbin  sys  usr
root@a87e160ee875:/# cd /root/
root@a87e160ee875:~# ls
test1
root@a87e160ee875:~# cd tst1
bash: cd: tst1: No such file or directory
root@a87e160ee875:~# cd test1
//&#x8FDB;&#x5165;test1 &#x6587;&#x4EF6;&#x5939;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;test1&#x6587;&#x4EF6;&#x5939;&#x91CC;&#x7684;&#x5185;&#x5BB9;&#x548C;&#x5BBF;&#x4E3B;&#x673A;test1&#x6587;&#x4EF6;&#x5939;&#x7684;&#x5185;&#x5BB9;&#x662F;&#x4E00;&#x6837;&#x7684;
root@a87e160ee875:~/test1# ls
1.txt  2.txt  b.txt
//&#x5728;&#x5BB9;&#x5668;&#x79CD;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x6587;&#x4EF6;
root@a87e160ee875:~/test1# touch a.txt
root@a87e160ee875:~/test1# echo aaaaawqewqewq > a.txt
root@a87e160ee875:~/test1# ls
1.txt  2.txt  a.txt  b.txt
root@a87e160ee875:~/test1# cat a.txt
aaaaawqewqewq
root@a87e160ee875:~/test1# exit
exit
[root@iZuf620p8rsr3faul3zsx6Z ~]# cd test1
//&#x9000;&#x51FA;&#x5BB9;&#x5668; &#x5728;&#x5BBF;&#x4E3B;&#x673A;&#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x4E00;&#x6837;&#x7684;&#x6587;&#x4EF6; &#x5185;&#x5BB9;&#x4E5F;&#x662F;&#x4E00;&#x6837;&#x7684;
[root@iZuf620p8rsr3faul3zsx6Z test1]# ls
1.txt  2.txt  a.txt  b.txt
[root@iZuf620p8rsr3faul3zsx6Z test1]# cat a.txt
aaaaawqewqewq

Original: https://www.cnblogs.com/Dewumu/p/16030921.html
Author: 德乌姆列特
Title: Docker基本命令

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/606542/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • Jedis和redisTemplate 共用问题–序列化不一致(生产事故->解决->两个redisTemplate)

    Jedis和redisTemplate 共用问题老项目用Jedis,放入redis中,用的是比较老的框架,还进行序列化. 用redisTemplate试了下拿不到.因为序列化的方式…

    Linux 2023年5月28日
    090
  • 这 BUG,绝了

    上周只上了三天班,但我也丝毫不敢懈怠,BUG 更是一个也没少写。 看着满屏幕的 ERROR,我陷入沉思。为什么我写的代如此烂,无法像大牛们写的那般优雅? 越想越自卑,越想越抑郁。我…

    Linux 2023年6月7日
    0108
  • Mysql数据库语言学习的路线

    对于我们数据库的学习,不管是测试人员还是开发人员以及我们的DBA来说重点都是SQL;但是我们的SQL可以分多少类型,学习重点又是在哪里呢,本文仅仅针对测试人员来展开说明: SQL:…

    Linux 2023年6月14日
    090
  • bash shell相关知识

    shell与bash 什么是shell ——以上图片摘自《鸟哥的Linux私房菜》 系统核心不能随意地被操作,所以就设计出了壳程序shell,一方面保护了系统核心,另一方面提供了人…

    Linux 2023年6月7日
    0119
  • Linux同时输出到管道和标准输出

    想使用Shell脚本对某文本文件中无序的一列数字排序并输出求和结果,文本如下所示: 421350 开头的命令只能输出求和结果,不能同时输出排序结果: [En] The comman…

    Linux 2023年5月27日
    090
  • gitlab服务yum源安装详细步骤(centos7)

    gitlab服务yum源安装详细步骤(centos7) 概述 GitLab是利用Ruby on Rails一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进…

    Linux 2023年6月8日
    097
  • Redis 常用五种数据类型编码

    1.String 1.1 常用命令 (1)设置值 set key value [ex seconds] [px milliseconds] [nx|xx] set命令有几个选项: …

    Linux 2023年5月28日
    099
  • 关于建设博客的事

    今天晚上到教室之后看到好多人在写简历,都在为周六的招聘会而准备,看了旁边同学的简历,里面有个个人网站,我点开一看是他的掘金博客,我突然想到了我老早之前注册的博客园的账号,一篇文章也…

    Linux 2023年6月7日
    0108
  • CentOS 7替换默认软件源

    安装CentOS 7后,默认源在国外,可以替换为国内的源以提升访问速度 参考https://mirrors.ustc.edu.cn/help/centos.html sudo vi…

    Linux 2023年6月6日
    091
  • Cisco GNS3教程,GNS3搭建IPv6 6rd环境,Linux 配置 IPv6 6rd详析

    Cisco GNS3 IPv6 6rd实验 1、回顾 前文:https://www.cnblogs.com/kingpop/p/14054321.html在描述Cisco GNS3…

    Linux 2023年6月6日
    0101
  • c++仿照go语言的error,函数返回值封装

    c++仿照go语言,程序返回错误时,可以附加错误信息 #ifndef __ERRORMSG_H_ #define __ERRORMSG_H_ #include struct Err…

    Linux 2023年6月14日
    092
  • Linux查看服务器内存、磁盘、cpu、网络占用、端口占用情况

    1、查看物理CPU个数:cat cat /proc/cpuinfo | grep “physical id” | sort | uniq | wc -l2、…

    Linux 2023年6月13日
    0138
  • 数据结构——光纤网络设计

    设计进度安排 1、分析居民区光纤网络的数据属性,并依据光纤铺设的功能要求,确定算法设计方案; 2、完成网络光纤铺设的数据结构设计工作,包括图文件的结构与存储结构、最小生成树的存储结…

    Linux 2023年6月6日
    091
  • Linux 文件查看命令

    文件查看命令 1、cat:从第一行开始显示文件内容 使用方式:cat 文件 或 文件路径 例如:cat ifcfg-eth0 或 cat /etc/sysconfig/networ…

    Linux 2023年6月14日
    0105
  • 记一次 android 线上 oom 问题

    背景 公司的主打产品是一款跨平台的 App,我的部门负责为它提供底层的 sdk 用于数据传输,我负责的是 Adnroid 端的 sdk 开发。 sdk 并不直接加载在 App 主进…

    Linux 2023年6月6日
    0113
  • Prometheus+Grafana监控-基于docker-compose搭建

    前言 Prometheus Prometheus 是有 SoundCloud 开发的开源监控系统和时序数据库,基于 Go 语言开发。通过基于 HTTP 的 pull 方式采集时序数…

    Linux 2023年6月7日
    093
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球