docker 命令
首页->学习资料->微服务治理->docker 关键词: 发布时间:2018-04-26 16:49:58 浏览次数:2709

image.png


列出镜像:

(sudo)docker image list


将当前用户添加到docker组中(权限修改),成功后命令前可以不用敲sudo了

sudo groupadd docker

sudo gpasswd -a 当前用户名 docker

sudo service docker restart

如果在虚拟机中,先退出再重新登录可使修改生效


从官方(https://hub.docker.com/explore/  )获取镜像:

docker pull 镜像名



运行一个docker镜像
docker run 镜像名

或者先docker create xx

再docker start xx



命令大全:

[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# docker


Usage: docker COMMAND


A self-sufficient runtime for containers


Options:

      --config string      Location of client config files (default "/root/.docker")

  -D, --debug              Enable debug mode

  -H, --host list          Daemon socket(s) to connect to

  -l, --log-level string   Set the logging level

                           ("debug"|"info"|"warn"|"error"|"fatal") (default "info")

      --tls                Use TLS; implied by --tlsverify

      --tlscacert string   Trust certs signed only by this CA (default

                           "/root/.docker/ca.pem")

      --tlscert string     Path to TLS certificate file (default

                           "/root/.docker/cert.pem")

      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")

      --tlsverify          Use TLS and verify the remote

  -v, --version            Print version information and quit


Management Commands:

  config      Manage Docker configs

  container   Manage containers

  image       Manage images

  network     Manage networks

  node        Manage Swarm nodes

  plugin      Manage plugins

  secret      Manage Docker secrets

  service     Manage services

  swarm       Manage Swarm

  system      Manage Docker

  trust       Manage trust on Docker images

  volume      Manage volumes


Commands:

  attach      Attach local standard input, output, and error streams to a running container

  build       Build an image from a Dockerfile

  commit      Create a new image from a container's changes(将容器生成新镜像,
                   如:docker commit -a "www.hu-rong.com" -m "php7.4-fpm+swoole4.6.3扩展" ece00894b5af hurong241/php74:swoole4.6.3)

  cp          Copy files/folders between a container and the local filesystem

  create      Create a new container(创建容器,如:docker create nginx)

  diff        Inspect changes to files or directories on a container's filesystem

  events      Get real time events from the server

  exec        Run a command in a running container(在容器中运行命令,相当于登录到容器中进行交互操作:docker exec -it 763140d6c7fa /bin/bash)

  export      Export a container's filesystem as a tar archive

  history     Show the history of an image

  images      List images(镜像列表:docker images)

  import      Import the contents from a tarball to create a filesystem image

  info        Display system-wide information

  inspect     Return low-level information on Docker objects

  kill        Kill one or more running containers(杀掉容器,如果暂停不起作用时可以用这个:docker kill 容器id)

  load        Load an image from a tar archive or STDIN

  login       Log in to a Docker registry

  logout      Log out from a Docker registry

  logs        Fetch the logs of a container(查看容器日志:docker logs -f 容器id,类似tail -f)

  pause       Pause all processes within one or more containers(暂停容器:docker pause 容器id)

  port        List port mappings or a specific mapping for the container

  ps          List containers(查看容器列表:docker ps -a)

  pull        Pull an image or a repository from a registry(从仓库中拉取镜像:docker pull nginx)

  push        Push an image or a repository to a registry

  rename      Rename a container

  restart     Restart one or more containers(重启容器:docker restart 容器id)

  rm          Remove one or more containers(删除容器,如果删除不掉先要将容器暂停:docker rm 容器id)

  rmi         Remove one or more images

  run         Run a command in a new container(运行容器,如:

docker run --name nginx-test -p 8080:80 -d -c 400 nginx
参数说明:
--name nginx-test:容器名称。
-p 8080:80: 端口进行映射,将本地 8080 端口映射到容器内部的 80 端口。
-c 分配cpu使用量,当容器出现cpu争抢资源时才有效,假如有2个容器在运行,一个设置为400,一个设置为600相当于一个最多可占用40%一个最多可占用60%的cpu资源
-m 分配内存占用,如-m 200M
--memory-swap 内存加交互区总大小,要设置得比-m大,如--memory-swap=300M,则实际交换区为100M(300-200)
-d 设置容器在在后台一直运行。
-v 挂载本地目录到容器中,如 本地目录:/var/lib/mysql (docker run -d --name mysql -p 3306:3306 -v 本地目录:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=xxx)
--restart具体参数值详细信息:
       no        容器退出时,不重启容器;
       on-failure    只有在非0状态退出时才重新启动容器;
       always      无论退出状态是如何,都重启容器;
修改已有容器为自动用重启,使用update
docker update --restart=always 容器ID(或者容器名)

内存限制相关的参数

执行docker run命令时能使用的和内存限制相关的所有选项如下。

选项描述
-m,--memory内存限制,格式是数字加单位,单位可以为 b,k,m,g。最小为 4M
--memory-swap内存+交换分区大小总限制。格式同上。必须比-m设置的大
--memory-reservation内存的软性限制。格式同上
--oom-kill-disable是否阻止 OOM killer 杀死容器,默认没设置
--oom-score-adj容器被 OOM killer 杀死的优先级,范围是[-1000, 1000],默认为 0
--memory-swappiness用于设置容器的虚拟内存控制行为。值为 0~100 之间的整数
--kernel-memory核心内存限制。格式同上,最小为 4M

 

 save        Save one or more images to a tar archive (streamed to STDOUT by default)

  search      Search the Docker Hub for images

  start       Start one or more stopped containers(启动容器:docker start 容器id)

  stats       Display a live stream of container(s) resource usage statistics

  stop        Stop one or more running containers(停止容器:docker stop 容器id)

  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

  top         Display the running processes of a container

  unpause     Unpause all processes within one or more containers(暂停容器:docker unpase 容器id)

  update      Update configuration of one or more containers

  version     Show the Docker version information

  wait        Block until one or more containers stop, then print their exit codes


Run 'docker COMMAND --help' for more information on a command.


赞:(0)
踩:(0)
相关文章
docker容器中开启php扩展,制成新镜
docker容器中安装扩展后制成新镜像
如何在docker容器外执行php artisa
docker容器如何执行composer insta
docker容器内无法上网ping不通外网
将docker中的文件拷贝到docker外
docker中nginx可以访问html无法访
docker容器中安装amqp扩展
docker安装及入门教程
centos7上安装docker
热门文章
win7中将文件拷贝到虚拟机linux下
phpexcel设置行高及列宽,背景颜色,
rabbitmq无法启动
intellij idea不显示git push按钮
php7中使用mongodb的aggregate进行
laravel页面静态化的方法
centos7.4 64位下swoole安装及配置
navicate连接mycat报1184错误
curl设置超时不起作用(CURLOPT_TIM
devops-jenkins容器为pending状态
好评文章
phpexcel设置行高及列宽,背景颜色,
php7中使用mongodb的aggregate进行
intellij idea打开文件所在文件夹
windows下使用MongoDB Compass Com
win7中将文件拷贝到虚拟机linux下
laravel 中悲观锁 & 乐观锁的使用
单点登录sso原理及php实现方式及de
navicate连接mycat报1184错误
rabbitmq无法启动
laravel整合dingo/api方法步骤:jwt
标签
rabbitmq mysql备份 elasticsearch golang swoole
我的项目
【github】www.github.com/hurong241
【码云】gitee.com/hu_rong/projects
【docker hub】hub.docker.com/repositories/hurong241
【packagist】packagist.org/users/hurong241/packages
站点信息
建站时间:2011年
文章数:623篇
浏览数:1357698
粤ICP备18028092号-1  微信:hurong241