Docker基础命令
2018-08-16 本文已影响0人
半斤代码
镜像
获取镜像
docker pull ubuntu
查看镜像信息
docker images
docker tag ubuntu:latest myubuntu:latest
docker inspect abc
docker history abc
搜寻镜像
docker search abc
删除镜像
docker rmi myubuntu:latest
创建镜像
// 基于已有镜像的容器创建
docker commit -m "Addded a new file" -a "Docker Newbee" a925cb40b3f0 test:0.1
// 基于本地模板导入
// 可以使用[OPENVZ模板](https://download.openvz.org/template/precreated/)来创建,或者用其他已导出的镜像模板来创建
cat ubuntu-14.04-x86_64-minimal.tar.gz | docker import - ubuntu:14.04
存出和载入镜像(类似iso镜像)
// 存出镜像
docker save -o ubuntu_14.04.tar ubuntu:14.04
// 载入镜像
docker load -i ubuntu ubuntu_14.04.tar
上传镜像(类似git push)
docker tag test:latest user/test:latest
docker push user/test:latest
容器
创建容器
// 新建容器
docker create -it ubuntu:latest
// 启动容器
docker start af
终止容器
docker stop af
进入容器
// attach命令(多个窗口是同步的)
docker attach abc
// exec命令
docker exec -it 243c32535da7 /bin/bash
删除容器
docker rm ce554267d7a4
导入和导出容器(类似快照)
// 导出容器
docker export -o test_for_run.tar ce554267d7a4
docker export ce554267d7a4 > test_for_run.tar
// 导入容器
docker import test_for_run.tar - test/ubuntu:v1.0
仓库
Docker Hub(官方仓库)
// 登录
docker login
// 基本操作
docker search centos
docker pull centos
// 自动创建-------
山寨仓库
// 时速云,daocloud....
docker pull index.tenxcloud.com/docker_library/node:latest
docker tag index.tenxcloud.com/docker_library/node:latest node:latest
私有仓库(类似gitlab)
// 使用registry镜像创建私有仓库
docker run -d -p 5000:5000 registry
docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
// 管理私有仓库
docker tag ubuntu:14.04 10.0.2.2:5000/test
docker push 10.0.2.2:5000/test
curl http://10.0.2.2:5000/v1/search
关闭安全性检查
DOCKER_OPTS="--insecure-registry 10.0.2.2:50000"
sudo sesrvice docker restart
docker pull 10.0.2.2:5000/test
docker tag 10.0.2.2:5000/test ubuntu:14.04