不做大哥好多年 不做大哥好多年
首页
  • MySQL
  • Redis
  • Elasticsearch
  • Kafka
  • Etcd
  • MongoDB
  • TiDB
  • RabbitMQ
  • 01.GO基础
  • 02.面向对象
  • 03.并发编程
  • 04.常用库
  • 05.数据库操作
  • 06.Beego框架
  • 07.Beego商城
  • 08.GIN框架
  • 09.GIN论坛
  • 10.微服务
  • 01.Python基础
  • 02.Python模块
  • 03.Django
  • 04.Flask
  • 05.SYL
  • 06.Celery
  • 10.微服务
  • 01.Java基础
  • 02.面向对象
  • 03.Java进阶
  • 04.Web基础
  • 05.Spring框架
  • 100.微服务
  • Docker
  • K8S
  • 容器原理
  • Istio
  • 数据结构
  • 算法基础
  • 算法题分类
  • 前置知识
  • PyTorch
  • 01.Python
  • 02.GO
  • 03.Java
  • 04.业务问题
  • 05.关键技术
  • 06.项目常识
  • 10.计算机基础
  • Linux基础
  • Linux高级
  • Nginx
  • KeepAlive
  • ansible
  • zabbix
  • Shell
  • Linux内核

逍遥子

不做大哥好多年
首页
  • MySQL
  • Redis
  • Elasticsearch
  • Kafka
  • Etcd
  • MongoDB
  • TiDB
  • RabbitMQ
  • 01.GO基础
  • 02.面向对象
  • 03.并发编程
  • 04.常用库
  • 05.数据库操作
  • 06.Beego框架
  • 07.Beego商城
  • 08.GIN框架
  • 09.GIN论坛
  • 10.微服务
  • 01.Python基础
  • 02.Python模块
  • 03.Django
  • 04.Flask
  • 05.SYL
  • 06.Celery
  • 10.微服务
  • 01.Java基础
  • 02.面向对象
  • 03.Java进阶
  • 04.Web基础
  • 05.Spring框架
  • 100.微服务
  • Docker
  • K8S
  • 容器原理
  • Istio
  • 数据结构
  • 算法基础
  • 算法题分类
  • 前置知识
  • PyTorch
  • 01.Python
  • 02.GO
  • 03.Java
  • 04.业务问题
  • 05.关键技术
  • 06.项目常识
  • 10.计算机基础
  • Linux基础
  • Linux高级
  • Nginx
  • KeepAlive
  • ansible
  • zabbix
  • Shell
  • Linux内核
  • Docker

    • 01.Docker介绍
    • 02.安装docker
    • 03.Docker镜像介绍
    • 04.docker命令
      • 01.镜像管理命令
      • 02.docker容器管理常用命令
        • 2.1 docker run常用参数
        • 2.2 docker 创建容器命令
        • 2.3 容器资源限制
      • 03.docker数据挂载到容器
    • 05.dockerfile使用
    • 06.docker-compose介绍
    • 07.docker-compose项目实战
  • K8S

  • 容器原理

  • Istio

  • 容器
  • Docker
xiaonaiqiang
2021-02-12
目录

04.docker命令

# 01.镜像管理命令

[root@linux-node4 diff]# docker help                           # 查看docker帮助
[root@linux-node4 diff]# docker image --help                   # 查看 docker中 镜像相关帮助
[root@linux-node4 diff]# docker image ls                       # 查看当前所有镜像
[root@linux-node4 diff]# docker image inspect nginx            # 查看指定镜像(nginx镜像)详细信息
[root@linux-node4 diff]# docker pull nginx:1.14                # 下载指定版本镜像 nginx
[root@linux-node4 diff]# docker image rm nginx:1.14            # 删除nginx 1.14版本
[root@linux-node4 diff]# docker image save nginx > nginx.tar   # 导出niginx镜像
1
2
3
4
5
6
7

# 02.docker容器管理常用命令

# 2.1 docker run常用参数

-d   # 后台运行容器,并返回容器ID;
-i   # 以交互模式运行容器,通常与 -t 同时使用;
-t   # 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
-P   # 随机端口映射,容器内部端口随机映射到主机的高端口
-p   # 指定端口映射,格式为:主机(宿主)端口:容器端口
--name="nginx-lb"   # 为容器指定一个名称;
--dns 8.8.8.8       # 指定容器使用的DNS服务器,默认和宿主一致;
1
2
3
4
5
6
7

# 2.2 docker 创建容器命令

[root@linux-node4 diff]# docker run --help                              # 查看创建容器帮助
[root@linux-node4 diff]# docker run -it centos                          # 创建centos镜像并进入终端
[root@linux-node4 diff]# docker run -d nginx                            # 后台启动nginx容器
[root@linux-node4 diff]# docker stop 6bb09dce461f                       # 关闭一个容器
[root@linux-node4 diff]# docker ps -l                                         # 查看最近运行的容器
[root@linux-node4 diff]# docker run -itd centos                         # 启用一个伪终端守护centos容器
[root@linux-node4 diff]# docker container run -d --name web3 -e test=123456 -p 8800:80 -h webhostname --restart always nginx
-d                   # 后台启动nginx容器
--name web3          # 自定义容器名字(默认会是一段随机字符串)
-e test=123456       # 启动容器添加变量 test=123456 (echo $test)
-p 8800:80           # 宿主机的8800端口映射到docker容器的80端口中
-h webhostname       # docker容器主机名 (a300f394af88)
--restart always     # 宿主机重启自动拉起这个docker容器
nginx                # 使用这个nginx镜像启动容器
注:http://192.168.56.12:8800/     访问这个docker  nginx
[root@linux-node4 diff]# docker logs web                                 # 查看上面启动的web容器的日志
[root@linux-node4 diff]# docker exec -it web bash                        # 进入容器web
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# 2.3 容器资源限制

'''1. 内存限额: 允许容器最多使用500M内存和100M的Swap,并禁用 OOM Killer '''
[root@linux-node4 diff]# docker run -d --name nginx03 --memory="500m" --memory-swap="600m" --oom-kill-disable nginx

'''2. CPU限额:'''
[root@linux-node4 diff]# docker run -d --name nginx04 --cpus="1.5" nginx           # 允许容器最多使用一个半的CPU
[root@linux-node4 diff]# docker run -d --name nginx05 --cpus=".5" nginx            # 允许容器最多使用50%的CPU
1
2
3
4
5
6

# 03.docker数据挂载到容器

**更多详细内容请见:**https://www.cnblogs.com/xiaonq/p/10241045.html#i5

上次更新: 2024/3/13 15:35:10
03.Docker镜像介绍
05.dockerfile使用

← 03.Docker镜像介绍 05.dockerfile使用→

最近更新
01
04.数组双指针排序_子数组
03-25
02
08.动态规划
03-25
03
06.回溯算法
03-25
更多文章>
Theme by Vdoing | Copyright © 2019-2025 逍遥子 技术博客 京ICP备2021005373号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式