镜像拉取
// A code block
[unique@localhost ~]$ sudo docker pull username/repository:tag
启动本地容器
// A code block
localhost:Data sunkaixin$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
reg.docker.haha-inoc.com/hahabase/alios7u2 latest 43d2d59ab537 4 months ago 2.8GB
reg.docker.haha-inoc.com/soag/jpgmon_servicetest 1.0 3afd24b0b6b1 7 months ago 3.96GB
reg.docker.haha-inoc.com/sla/ipgmon 1.0 24bdf509bbda 15 months ago 2.97GB
reg.docker.haha-inoc.com/sla/jpgmon <none> 72d693f8898e 15 months ago 3.05GB
拉起本地镜像
// A code block
localhost:Data sunkaixin$ docker run -itd 3afd24b0b6b1
查找容器并进入
安装必要的软件
Docker tag
标记image
将本地映像与注册表上的存储库相关联的表示法是 username/repository:tag。标签是可选的,但建议使用,因为它是注册管理机构用来为Docker镜像提供版本的机制。为上下文提供存储库和标记有意义的名称,例如 get-started:part2。这会将图像放入get-started存储库并将其标记为part2。
现在,把它们放在一起来标记图像。docker tag image使用您的用户名,存储库和标记名称运行,以便将图像上载到所需的目标位置。该命令的语法是:
docker tag imageName username/repository:tag
docker build && commit
docker build命令用于根据给定的Dockerfile和上下文以构建Docker镜像。
docker build命令的使用格式:
docker build [OPTIONS] <PATH | URL | ->
- 常用OPTIONS选项说明
–build-arg,设置构建时的环境变量
–no-cache,默认false。设置该选项,将不使用Build Cache构建镜像
–pull,默认false。设置该选项,总是尝试pull镜像的最新版本
–compress,默认false。设置该选项,将使用gzip压缩构建的上下文
–disable-content-trust,默认true。设置该选项,将对镜像进行验证
–file, -f,Dockerfile的完整路径,默认值为‘PATH/Dockerfile’
–isolation,默认–isolation=“default”,即Linux命名空间;其他还有process或hyperv
–label,为生成的镜像设置metadata
–squash,默认false。设置该选项,将新构建出的多个层压缩为一个新层,但是将无法在多个镜像之间共享新层;设置该选项,实际上是创建了新image,同时保留原有image。
–tag, -t,镜像的名字及tag,通常name:tag或者name格式;可以在一次构建中为一个镜像设置多个tag
–network,默认default。设置该选项,Set the networking mode for the RUN instructions during build
–quiet, -q ,默认false。设置该选项,Suppress the build output and print image ID on success
–force-rm,默认false。设置该选项,总是删除掉中间环节的容器
–rm,默认–rm=true,即整个构建过程成功后删除中间环节的容器
// docker commit
docker commit -m "xxx" <容器 id> <镜像名称>:<tag>
docker push
//docer push
docker push username/repository:tag
step1——找到本地镜像的ID:docker images
step2——登陆Hub:docker login --username=username --password=password --email=email
step3——tag:docker tag <imageID> <namespace>/<image name>:<version tag eg latest>
step4——push镜像:docker push <namespace>/<image name>