docker的常用命令

一、 不输入sudo执行docker命令

  1、 直接切换到root用

 $ su - root

 

  2、 将当前用户添加到docker组(docker组的权限与root一样,需谨慎。)

# centos7命令
$ sudo gpasswd –a ${USER} docker

# ubuntu16命令
$ sudo usermod –aG docker ${USER}  

#启动服务生效,如果不生效,需重启系统     
$ sudo systemctl restart docker

 

二、 docker常用命令

  1、 搜索镜像

$ docker search ubuntu

 

  2、 使用pull命令下载镜像

$ docker pull ubuntu:latest

 

  3、 使用images命令列出镜像

$ docker images

 

  4、 使用run命令创建容器

$ docker run –i –t  --name hello ubuntu /bin/bash

 

  5、 查看容器列表

$ docker ps -a

 

  6、 使用start 命令启动容器

# 启动hello容器
$ docker start hello

 

  7、 使用restart命令连接容器

$ docker restart hello

 

  8、 使用attach连接容器

$ docker attach hello

 

  9、 使用exc命令从外部运行容器的命令

$ docker exec hello echo “Hello world”

 

  10、使用stop命令终止容器

$ docker stop hello

 

  11、使用rm命令删除容器

$ docker rm hello

 

  12、使用rmi命令删除镜像

$ docker rmi ubuntu

 

posted @ 2017-08-17 17:05  jefflee168  阅读(217)  评论(0编辑  收藏  举报