docker使用问题集锦

一、docker查看启动的容器信息

service docker stop/start 停止启动

docker ps 查看当前运行的镜像

sudo docker run -t -i c5ea139d0e47 /bin/bash   进入c5ea139d0e47 的镜像

一种是使用save和load命令

使用例子如下:

docker save ubuntu:load>/root/ubuntu.tar

docker load<ubuntu.tar

一种是使用export和import命令 (导出的是容器,不是镜像)

使用例子如下:

docker export 98ca36> ubuntu.tar

cat ubuntu.tar | sudo docker import – ubuntu:import

注意:运行导入的镜像的时候必须带command,否则启动报如下错误, 带入的参数在导出是通过 docker ps可查看COMMAND

需要注意两种方法不可混用。

 

 

二、启动docker时常用的参数

关于cpu的设置:

-c, –cpu-shares=0 CPU shares (relative weight)  设置cpu权重,取值0-1024,0代表1024

–cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period    单位是微秒

–cpu-quota=0 Limit the CPU CFS quota  单位是微秒,

–cpuset-cpus= CPUs in which to allow execution (0-3, 0,1)  指定使用的cpu 编号例如  0-3

–cpuset-mems= MEMs in which to allow execution (0-3, 0,1)

 

–memory=3G  使用内容

–restart=always 自动重启

例如: docker run -d -p 8050:8050 –memory=12G –cpu-shares=2 –cpuset-cpus=”0-3″ –restart=always scrapinghub/splash –maxrss 10000 –max-timeout 500

 

三、docker镜像的导入导出

docker ps -a 查看当前镜像和容器

docker export cbe3cb7799ed > update.tar 导出到文件

docker import – myimagesname < update.tar  导入为myimagesname 镜像名称

 

四、docker设置日志格式

/etc/docker/daemon.json

没有设置--log-driver时默认采用的是json-file格式

可配置日志格式,文件大小等参数

{

"log-driver": "json-file",

"log-opts": {

    "max-size": "10m",

    "max-file": "3",

    "labels": "production_status",

    "env": "os,customer"

  }

}

 

五、传递系统参数

docker run -d –hostname

–hostname:设置容器的主机名,仅本机可见。这种方式是写到/etc/hostname ,以及/etc/hosts 文件中,作为容器主机IP的别名,并且将显示在容器的bash中

六、常见的进入容器时的问题

  1. 容器里命令行换行是乱码问题

docker exec -it -e LINES=$(tput lines) -e COLUMNS=$(tput cols) 09dbd68a3b99 /bin/bash

LINES 与 COLUMNS固定

You May Also Like

About the Author: daidai5771

发表评论

电子邮件地址不会被公开。 必填项已用*标注