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)

大家都在看

  • CSS中content属性的妙用

    前言 本文讲解CSS中使用频率并不高的content属性,通过多个实用的案例,带你由浅入深的掌握content的用法,让代码变得更加简洁、高效。 定义 W3school中这样定义:…

    Linux 2023年6月7日
    0122
  • 搭建ES集群

    添加以下elasticsearch用户: bash;gutter:true; 1 useradd elasticsearch 2 passwd elasticsearch</…

    Linux 2023年6月8日
    077
  • Centos7 禁用IPV6地址的方法

    404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 contact@cnblogs.com 园子的商业化努力-困…

    Linux 2023年6月7日
    071
  • 服务器部署 Vue 和 Django 项目的全记录

    本篇记录我在一个全新服务器上部署 Vue 和 Django 前后端项目的全过程,内容包括服务器初始配置、安装 Django 虚拟环境、python web 服务器 uWSGI 和反…

    Linux 2023年6月7日
    0101
  • 运算符重载限制

    p387 5.表 11.1 中的大多数运算符都可以通过成员或非成员函数进行重载,但下面的运算符只能通过成员函数进行重载。 =:赋值运算符。 ():函数调用运算符。 []:下标运算符…

    Linux 2023年6月13日
    086
  • 计算机系统实验

    实验三 一 实验目的 理解堆栈结构,利用缓冲区进行代码攻击 二 准备工作 配置实验环境(IDA、gcc),阅读实验指导书 三 实验过程 0x01第一关 首先理解堆栈的结构 /* 第…

    Linux 2023年6月8日
    088
  • 离线版centos8安装docker笔记

    嗨嗨哈哈,已经很久没有坐下来胡编乱造一点笔记了,平时云服务器搞惯了,一个命令就安装好了docker了的,但这次生不逢时的新机房就没那么幸运了,有多不逢时超乎想象,不仅仅服务器没有外…

    Linux 2023年5月27日
    0118
  • 终于知道 Shell 中单引号双引号的区别了

    在编写 shell 脚本或输入命令时,你可能已经注意到大多数命令都可以使用单引号 或双引号, 这不仅适用于 shell 脚本,而且适用于所有 Bash 命令, 但是两种类型的引号以…

    Linux 2023年6月13日
    076
  • LeetCode-47. 全排列 II

    题目来源 题目详情 给定一个可包含重复数字的序列 nums , 按任意顺序 返回所有不重复的全排列。 示例 1: 输入: nums = [1,1,2]输出:[[1,1,2],[1,…

    Linux 2023年6月7日
    078
  • vue axios的二次封装

    1、axios的二次封装 BiliBili作者原地址,多多支持 npm i axios //下载axios 首先创建两个文件夹在src目录下;api和config 先在 confi…

    Linux 2023年6月7日
    066
  • 超算TOP500中的Linux占比——Operating System&Operating System Family

    2022-09-18-21:28:59 老师作业说明: TOP500中国超算占比,LINUX系统占比 说明:当时使用的是bing搜索,中国超算占比其实澎湃新闻什么的都有介绍,但是我…

    Linux 2023年6月6日
    091
  • ESXI系列问题整理以及记录——使用SSH为设备打VIB驱动包,同时提供一种对于ESXI不兼容螃蟹网卡(Realtek 瑞昱)的问题解决思路

    对于ESXI不兼容螃蟹网卡的问题,这里建议购买一张博通的低端单口千兆网卡,先使用博通网卡完成系统部署,再按照下文方法添加螃蟹网卡的VIB驱动,最后拆除博通网卡。 螃蟹网卡VIB驱动…

    Linux 2023年6月13日
    090
  • linux系统(centos)配置ssh免密登录

    linux系统(centos)配置ssh免密登录 背景 在日常使用时候,远程执行一些命令或脚本,交互式的输入密码有些不方便。故需配置免密登录。 用SSH命令行在A服务器上远程登录B…

    Linux 2023年6月8日
    090
  • docker-部署jumpserver

    Docker 部署 jumpserver 堡垒机 容器部署 jumpserver-1.4.10 服务端 #最好单一个节点 容器运行Mysql 5.6.46 #myql , redi…

    Linux 2023年6月14日
    095
  • CentOS7 安装高版本gcc, g++, gfortran等工具

    SCL(Software Collections)是一个CentOS/RHEL Linux平台的软件多版本共存解决方案,为用户提供一种方便、安全地安装和使用应用程序和运行时环境的多…

    Linux 2023年6月7日
    078
  • Redis 缓存更新一致性

    在使用 Redis 作为数据库缓存的场景中对数据的读取流程通常是先读取缓存如果命中则返回,未命中则从数据库读取并把数据写到缓存中。 当更新数据时则数据库和缓存都要进行更新,此时我们…

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