docker 常用命令整理

sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装 Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce
# Step 5: 启动docker服务
sudo service docker start
 
#注意应为全是sudo下载以及创建所以用
su用户(最高权限)
 

为了永久性保留更改,您可以修改 /etc/docker/daemon.json 文件并添加上 registry-mirrors 键值。

{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}

然后重新启动下docker服务

systemctl restart docker
 
镜像
搜索 
 docker search ubuntu
  docker search -f is-official=true redis
 
查看本地镜像
 docker  images
 
下载镜像
docker pull ubuntu
docker pull ubuntu:16.04
 
 
删除镜像
docker rmi ubuntu        (默认删除latest版本)
docker rmi 8cef...          (image id)
docker rmi -f ubuntu      (强行删除)
 
 
镜像保存
docker save  ubuntu  centos > abc.tar (应用:拷贝给别人)
docker save  ubuntu  centos -o abc.tar (应用:拷贝给别人)
 
 
加载镜像
docker load -i abc.tar
 
重命名镜像
docker tag  ubuntu  new_name
 
 
镜像详细信息
docker image inspect ubuntu
 
 
docker  inspect -f "{{.ContainerConfig.Hostname}}" ubuntu
或者
docker image inspect -f "{{.ContainerConfig.Hostname}}" ubuntu
 
 
容器
 
查看
docker ps
docker ps -a
 
创建
docker create ubuntu
docker create ubuntu  ls -a
docker create --name hello_world  ubuntu
docker create ubuntu ls -a(ls -a 为command命令)
docker create -ti  --name python_ceshi centos python(创建带交互模式的) //用这种--打开就启动python
  
 
删除
docker  rm -f  3a33
 
 
启动命令
docker start -ai python_ceshi (交互模式) !!!!
 
 
run命令 
docker run  ==    docker create  + docker start -a 
docker run centos -ti python
docker run  -d -ti centos python   ==docker create + docker start
docker run  -dti centos python(一直运行)
 
 
关闭容器
docker stop -t 2 name(2秒停止)
 
kill -l 查看kill信号
 
stop   ==  SINGTERM  -t 5 SIGKILL
 
docker kill  -s ''
docker kill name 强制关闭
 
暂停命令
docker pause name 暂停命令
docker unpause name 取消暂停命令
 
重启容器
docker restart   name  ==start + stop
 
停止后删除
docker run  -dti --rm centos bash
 
重要命令!!!!
必须要在在容器运行时候! 
docker attach name  把命令绑定到pid =1 那个进程住进程 (就相当于运行程序!!!!)(不懂直接用一下就明白了)
 
ps -A 查看进程
 
在容器中运行一个命令
docker exec  -ti name bash (相当于新开一个bash命令不影响主进程)
 
 容器提交 ->生成新的镜像(类似于继承关系)---保存原数据---!!!!!!!!!!!!!!!!用的多  多个layer
docker commit  -a authors  -m install_some_tools    my_centos:v1.0
 
 
容器打包(生一个整体文件的样子)---不保存原数据  一个layer
docker export -o new_centos.tar name
 
导入容器
docker import -m "is_a_message" new_centos.tar  centos_net2_name:V1.0
 
 
 
 
 
 
 
 
 
 
posted @ 2019-08-18 16:13  Mr_Smith  阅读(152)  评论(0编辑  收藏  举报