sudo yum remove docker
yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun
sudo systemctl enable docker
sudo systemctl start docker
sudo groupadd docker
sudo usermod -aG docker $USER
docker run hello-world
/etc/docker/daemon.json
{
"registry-mirrors":["http://hub-mirror.c.163.com"]
}
systemctl restart docker
docker info
docker ps -a
docker rm -f containID
docker rmi hello-world
------------------------------------------------------
mkdir mynginx
cd mynginx
touch Dockerfile
FROM nginx
RUN echo '
Hello ,Docker ! ' /usr/share/nginx/html/index.html
COPY a.html /usr/share/nginx/html/
docker build -t mynginx:1.0 .
ADD指令和COPY的格式和性质基本一致。但是在COPY基础上增加了一些功能,比如原路径可以是一个URL
所有的文件复制都用copy
仅在需要自动解压缩的场合使用ADD
docker build -t mynginx:2.0 .
docker run --name mynginx2 -p 80:80 mynginx:2.0
dockere exec -it mynginx2 /bin/bash
ENTRYPOINT入点口
ENTRYPOINT 的目的和CMD一样,都是在制定容器启动程序及参数。
ENTRYPOINT在运行时也可以替代,不过比CMD要略显繁琐,需要通过docker run 的参数 --entrypoint来制定
当制定了 ENTRYPOINT后,CMD的含义就发生了改变,不再是直接的运行七名了,而是将CMD内容作为参数传给
ENTRYPOINT指令,换句话说实际执行时,将变为
""
ENV
ENV ==
docker run -d -v mydata:/data xxxxx
EXPOSE声明端口
这只是一个声明,在运行时并不会因为这个声明就会开启这个端口的服务。
在Dockerfile中写入这样的声明有两个好处:
1.是邦族镜像使用者理解这个镜像服务的守护端口,以方便配置映射;
2.在运行时使随机端口影射时,也就是docker run -P 时,会自动随机映射EXPOSE的端口
WORKDIR指定工作目录
使用WORKDIR指令可以来制定工作目录(或者称当前目录),以后各层的当前目录就被改为指定的目录,如该
目录不存在,WORKDIR会帮你建立目录
之前提到一些初学者常犯的错误是把Dockerfile等同于Shell脚本来书写,这种错误的理解可能会导致
出现下面这样的错误:
RUN cd /app
RUN echo "hello" > world.txt
如果将这个Dockerfile进行构建镜像运行后,会发现找不到 /app/world.txt文件
HEALTHCHECK
一个镜像制定了HEALTHCHECK指令后,用其启动容器,初始状态会为starting,在其执行健康检查成功后变为
healthy,如果连续一定次数失败,则会变为unhealthy.
HEALTHCHECK 支持下列选项:
--interval=<间隔>:两次健康检查的间隔时间,默认为30秒;
--timeout=<时长> :健康检查命令运行超时时间,如果超过这个时间,本次健康检查就被视为失败,默认30秒
--retries=<次数> :当连续失败指定次数后,则将容器状态视为unhealthy,默认三次
为了帮助排障,健康检查命令的输出(包括stdout以及stderr)都会被存储于健康状态里,可以用docker inspect
来查看。
docker save 和 docker load
docker save nginx|gzip>nginx-latest.tar.gz
docker load -i nginx-latest.tar.gz
-------------------------------------------------------
FROM tomcat:7.0.88-jre8
MAINTAINER LCM
EVN TOMCAT_BASE /usr/local/tomcat
#复制war包
COPY ./session-web.war $TOMCAT_BASE/webapps/
docker build -t session-web:latest .
docker build -t session-web:3.0 .
docker run --name session-web -d -p 8888:8080 session-web:latest
docker run --name session-web -d -p 18888:8080 session-web:2.0
docker run --name session-web -d -p 28888:8080 session-web:3.0
192.168.40.182:8888/session-web/user/login
---------------------------------------------------------
docker login
docker logout
docker search
docker pull
docker push
docker run --name registry -d -p 5000:5000 --restart=always -v /opt/data/registry:/var/lib/registry registry
docker tag session-web:latest 127.0.0.1:5000/session-web:latest
docker push 127.0.0.1:5000/session-web:latest
curl 127.0.0.1:5000:/v2/_catalog
curl 192.168.40.182:5000:/v2/_catalog
docker image rm 127.0.0.1:5000/session-web:latest
docker pull 127.0.0.1:5000/session-web:latest
docker push 127.0.0.1:5000/session-web:latest
docker 不允许非https推送镜像
对于使用systemd的系统,请在/etc/docker/daemon.json
{
"registry-mirrors":["http://hub-mirror.c.163.com"],
"insecure-registries":["192.168.40.182:5000"]
}
{
"registry-mirrors":["http://hub-mirror.c.163.com"],
"insecure-registries":["129.28.178.45"]
}
docker tag hello-world:latest 192.168.40.182:5000/hello-world:latest
docker push 192.168.40.182:5000/hello-world:latest
docker pull 192.168.40.182:5000/hello-world:latest
curl http://192.168.40.182:5000/v2/_catalog
docker pull harbor.laotapo.com/common/eureka-server:latest
docker tag docker.io/hello-world harbor.laotapo.com/common/hello-world:latest
docker tag docker.io/hello-world 47.94.250.104:1180/common/hello-world:latest
docker tag hello-world 129.28.178.45/library/hello-world:latest
docker tag hello-world 129.28.178.45/common/hello-world:v1.0
docker push 私服地址/仓库项目名/镜像名:标签
docker push 129.28.178.45/library/hello-world:latest
docker push 129.28.178.45/common/hello-world:v1.0
docker push harbor.laotapo.com/common/hello-world:latest
docker push harbor.laotapo.com/common/eureka-server:latest
docker push docker.io/hello-world 47.94.250.104:1180/common/hello-world:latest
docker tag hello-world harbor.laotapo.com/common/hello-world:latest
CentOS7如何将Docker升级到最新版
1.查找主机上关于Docker的软件包
rpm -qa | grep docker – – 列出包含docker字段的软件的信息
2.使用yum remove卸载软件
yum remove docker-1.13.1-53.git774336d.el7.centos.x86_64
3.使用curl升级到最新版
curl -fsSL https://get.docker.com/ | sh
4.重启Docker
# systemctl restart docker
----------------------------------------------------
harbor安装
https://www.cnblogs.com/pangguoping/p/7650014.html
docker-compose 安装
yum install python-pip
pip install docker-compose
docker-compose --version
pip uninstall docker-compose
wget https://github.com/vmware/harbor/releases/download/v1.2.0/harbor-offline-installer-v1.2.0.tgz
配置文件为:/usr/local/harbor/harbor.cfg
配置的内容为:
#禁止用户注册
self_registration = off
#设置只有管理员可以创建项目
project_creation_restriction = adminonly
执行安装命令
./install.sh