美文网首页
docker常见技巧

docker常见技巧

作者: 小骆驼与秀秀 | 来源:发表于2021-03-08 22:36 被阅读0次

docker常见技巧

查看当前docker本地已有哪些镜像

docker image ls

docker pull报错

Using default tag: latest
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

可能的原因是docker没启动,解决办法如下:

service docker start

docker pull慢,换源

docker pull 镜像会有点慢,而且会超时,下面介绍换腾讯云镜像的办法

新增配置文件

vi /etc/docker/daemon.json

内容如下

{
        "registry-mirrors": [
                "https://mirror.ccs.tencentyun.com"
        ]
}

查看配置是否生效

docker info

会看到以下打印:

 Registry Mirrors:
  https://mirror.ccs.tencentyun.com/

即可验证配置已生效,但需要重启docker

重启docker

sodu systemctl restart docker

接着,尽情享受飞速下载之旅

删除docker镜像

docker image rm xxx // xxx填入镜像id

如果需要强制删除,则在rm后面加入 -f 参数

查看当前运行的镜像

docker ps

其中,ps还支持更多选项,比如:

docker ps --help

得到输出

Usage:  docker ps [OPTIONS]

List containers

Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -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 numeric IDs
  -s, --size            Display total file sizes

比如,查看所有的镜像(不管是否在运行中)可以执行以下命令:

docker ps -a

docker 启动某个镜像

初次启动

docker run -d --name jenkins -p 8080:8080 -p 50000:50000 jenkins/jenkins

重新启动某个镜像

先用docker ps -a找到想要重启的镜像的镜像id,然后使用以下命令:

docker restart xxx // xxx 为镜像id

docker查看镜像日志

docker logs xxx // xxx填入镜像id

相关文章

网友评论

      本文标题:docker常见技巧

      本文链接:https://www.haomeiwen.com/subject/nwwmqltx.html