docker
#檢視docker運作程序
docker ps
#檢視docker的所有服務
docker ps -a
#docker下載下傳鏡像
docker pull centos #預設為最新的版本
#docker檢視鏡像
docker image
#docker删除
docker rmi images:ID
#建立容器
docker run -itd centos:lastest bash
#使用基礎鏡像建立一個容器:
docker run --name centos1 -itd centos:latest /bin/bash
#進入容器
docker exec -it 5c77e533be65 bash
#容器打包成鏡像:
docker commit afcaf46e8305 centos-vim(鏡像名稱)
建立Dockerfile目錄:
mkdir -pv /opt/dockerfile/system/{centos,redtar,ubuntu}
mkdir -pv /opt/dockerfile/web/{nginx/boss/{nginx-pre,nginx-online},jdk/{jdk7,jdk6},tomcat/boss/{tomcat-pre,tomcat-online}}
cd /opt/dockerfile/system/centos
vim Dockerfile
#Centos Base Image
FROM docker.io/centos:7.2.1511
MAINTAINER guoshaoliang "[email protected]"
RUN useradd -u 2000 www
RUN rm -rf /etc/yum.repo.d/*
RUN yum clean all
ADD *.repo /etc/yum.repo.d/
RUN yum makecache
RUN yum install -y vim wget tree pcre pcre-devel gcc gcc-c++ zlib zlib-devel openssl openssl-devel iproute net-tools iotop unzip zip iproute ntpdate nfs-utils tcpdump
準備附件檔案:
凡是使用ADD指令或者COPY指令添加到鏡像裡面的檔案都要提前準備好。
[[email protected] centos]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected] centos]# wget http://mirrors.aliyun.com/repo/epel-7.repo
[[email protected] centos]# docker build -t 172.16.101.239/images/centos7.2.1511-base .
#推薦将每個鏡像的建構指令寫成腳本儲存到目前目錄,友善後期使用,如:
[[email protected] centos]# cat build-command.sh
#!/bin/bash
docker build -t 172.16.101.239/images/centos7.2.1511-base .
#建構開始:
Dockerfile 建立完成後,可以使用 docker build 指令根據 Dockerfile 建構一個鏡像。
1. 首先準備好 Dockerfile :
2. 執行建構指令: docker build -t second:v1.0 .
注意最後有個點,代表使用目前路徑的 Dockerfile 進行建構 -t second : v1.0 給新建構的鏡像取名為 second, 并設定版本為 v1.0 。
****************centos鏡像上傳到harbor************************************
#docker下載下傳鏡像
docker pull centos
#docker 打标簽鏡像
[[email protected] centos]# docker tag centos:latest 172.16.101.239/images/centos:v2.1
#docker 上傳鏡像
[[email protected] centos]# docker push 172.16.101.239/images/centos:v2.1
Docker重命名鏡像名稱和TAG
# docker tag IMAGEID(鏡像id) REPOSITORY:TAG(倉庫:标簽)