https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/
如果你之前安装过 docker,请先删掉
sudo yum remove docker docker-common docker-selinux docker-engine
安装一些依赖
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
根据你的发行版下载repo文件:
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
把软件仓库地址替换为 TUNA:
sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
最后安装:
sudo yum makecache fast
sudo yum install docker-ce
- 1)获取镜像, 修改镜像, 镜像版本,打包镜像
- 2)容器创建 启动 查看状态 停止, 容器的网络端口映射.
- 3)DockerFile 为解析,如何编写DockerFile
docker pull 192.168.2.50/bg-devl/admin-api:2.1.22
[ue@VM_210_13_centos ~]$ docker commit -m '我的修改--106' user-center user-center:106
sha256:1a0c6c661f3fe7e1aeca9b6d71294713e03f8b9a15b435f2c96dd24b8d22493b
[ue@VM_210_13_centos ~]$ docker commit -a 'hangzhouOfChina' -m '我的修改--106' user-center user-center:1077
sha256:83b6ed8255bda41e66cc65bf4404421943b535e44c83048ec51c75489df68d4a
[ue@VM_210_13_centos ~]$ docker history user-center:1077
IMAGE CREATED CREATED BY SIZE COMMENT
83b6ed8255bd 4 minutes ago /usr/sbin/s 1.95 MB 我的修改--106
80aa165dc3ed 2 years ago /usr/sbin/ 91.2 MB
<missing 5 years ago /bin/bas 63.4 MB
[ued@VM_210_13_centos ~]$ docker images user-center
REPOSITORY TAG IMAGE ID CREATED SIZE
user-center 1077 83b6ed8255bd 6 minutes ago 1.2 GB
user-center 106 1a0c6c661f3f 7 minutes ago 1.2 GB
[ued@VM_210_13_centos ~]$ docker images user-center -a
REPOSITORY TAG IMAGE ID CREATED SIZE
user-center 1077 83b6ed8255bd 6 minutes ago 1.2 GB
user-center 106 1a0c6c661f3f 7 minutes ago 1.2 GB
[ucmed@VM_210_13_centos ~]$ docker tag
"docker tag" requires exactly 2 argument(s).
See 'docker tag --help'.
Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
[ued@VM_210_13_centos ~]$ docker tag user-center:1077 user-center:2.0.0
[ued@VM_210_13_centos ~]$ docker images user-center -a
REPOSITORY TAG IMAGE ID CREATED SIZE
user-center 1077 83b6ed8255bd 10 minutes ago 1.2 GB
user-center 2.0.0 83b6ed8255bd 10 minutes ago 1.2 GB
user-center 106 1a0c6c661f3f 11 minutes ago 1.2 GB
导出
[ued@VM_210_13_centos ~]$ docker save -o user-center200.tar user-center:2.0.0
[ued@VM_21013_centos ~]$ tar -zcvf user-center200.tar.gz user-center200.tar
[ud@VM_210_13_centos ~]$ ls -lh user-center200.tar*
-rw------- 1 ucmed root 1.2G Jan 4 18:32 user-center200.tar
-rw-r--r-- 1 ucmed root 679M Jan 4 18:34 user-center200.tar.gz
生产服务器上导入
[ud@VM_210_13_centos ~]$ docker load -i user-center200.tar
或者
[ud@VM_210_13_centos ~]$ docker load < user-center200.tar
Loaded image: user-center:2.0.0
### 容器导出镜像
docker export -o nginx-test.tar nginx-test
docker import nginx-test.tar nginx:imp
[ued@VM_210_13_centos ~]$ docker export -o hidoc.tar hidoc
[ued@VM_210_13_centos ~]$ docker import hidoc.tar hidoc:3.5
sha256:41914a0059c4aca4e40efef48f8be61a90ae70468c9d91f78e311a63e09fd880
[ued@VM_210_13_centos ~]$ docker images hidoc
REPOSITORY TAG IMAGE ID CREATED SIZE
hidoc 3.5 41914a0059c4 14 seconds ago 773 MB
$ docker run -it --restart=always ubuntu:16.04 /bin/bash
[ued@V_centos]$docker-compose -f docker-compose-304.yml down cnhangzhou-project
[ued@V_centos]$docker-compose -f docker-compose-304.yml pull cnhangzhou-project
[ued@V_centos]$docker-compose -f docker-compose-304.yml up -d
[ued@V_centos]$docker cp ali-pay-1.1.8-31-noxml.jar cnhangzhou-project:/opt/tomcat/webapps/ROOT/WEB-INF/lib/
[ued@V_centos]$docker exec -it cnhangzhou-project rm -f /opt/tomcat/webapps/ROOT/WEB-INF/lib/ali-pay-1.1.8-noxml-noxml.jar
[ued@V_centos]$docker exec -it cnhangzhou-project ls -lsh /opt/tomcat/webapps/ROOT/WEB-INF/lib/ali-pay*
[ued@V_centos]$docker ps -a
[ued@V_centos]$ sudo docker run -v /etc/hosts:/etc/hosts --name="ugateway" -v /home/ucmed/logs/cnhangzhou-u/ugateway/:/opt/logs/gateway --network cnhangzhou-u --network-alias gateway -p 8157:8030 \
-e JAVA_OPTS="-Dapp.id=ugateway -Denv=local -Xmx200m -Xmn50m -XX:MaxMetaspaceSize=80m -XX:MaxDirectMemorySize=25m -Xss512k -XX:+PrintGCDetails -Xloggc:/opt/gc.log" \
--env-file=env/common.env --env-file=env/gateway.env \
--restart=always -d ccr.ccs.tencentyun.com/big-d/gate:3.2.2s
[ued@V_centos]$ docker exec -it gateway-containerName bash
[ued@V_centos]$docker cp ali-pay-1.1.8-31-noxml.jar cnhangzhou-project:/opt/tomcat/webapps/ROOT/WEB-INF/lib/
$docker exec -it cnhangzhou-project rm -f /opt/tomcat/webapps/ROOT/WEB-INF/lib/ali-pay-1.1.8-noxml-noxml.jar
docker exec -it cnhangzhou-project ls -lsh /opt/tomcat/webapps/ROOT/WEB-INF/lib/ali-pay*
[ued@V_centos]$ docker inspect gateway
$ docker run -it -m 100M --oom-kill-disable --restart=always ubuntu:16.04 /bin/bash
Memory reservation 是一种软性机制,
它不保证任何时刻容器使用的内存不会超过--memory-reservation限定的值,
它只是确保容器不会长时间占用超过--memory-reservation限制的内存大小。
$ docker run -it -m 500M --memory-reservation 200M ubuntu:16.04 /bin/bash
CFS 周期的有效范围是 1ms1s,对应的--cpu-period的数值范围是 10001000000。
而容器的 CPU 配额必须不小于 1ms,即--cpu-quota的值必须 >= 1000。
可以看出这两个选项的单位都是 us。
$docker run -it --cpuset-cpus="1,3" ubuntu:14.04 /bin/bash
$ docker run --rm --name test01 --cpu-cpus 1 --cpu-quota=50000 --cpu-period=50000 deadloop:busybox-1.25.1-glibc
$ docker run --rm --name test01 -m 500M --memory-reservation 200M --cpuset-cpus="1"\
--cpu-quota=50000 --cpu-period=50000 ccr.ccs.tencentyun.com/big/doc:1.0.0
user.center.url = ${C_USER_CENTER_URL:http://10.105.91.26:8080/userCenterUCMED} third.access.token = ${THIRD_ACCESS_TOKEN}
FROM ccr.ccs.tencentyun.com/big-d/alpine-java:0.0.2
#FROM 192.168.2.50/openjdk:8-jdk-alpine-tool-tini
#FROM 192.168.2.50/openjdk:8-jdk-alpine-tomcat85-tini
COPY target/ROOT.war /opt/tomcat/webapps/ROOT.war
COPY config-cache/cnhangzhou-project+default+application.properties /opt/data/cnhangzhou-project/config-cache/cnhangzhou-project+default+application.properties
RUN mkdir -p /data/appdatas/cat
COPY client.xml /data/appdatas/cat/client.xml
RUN cd /opt/tomcat/webapps/ \
&& mkdir ROOT \
&& unzip -o ROOT.war -d ROOT \
&& rm ROOT.war
EXPOSE 8080 12581
CMD ["catalina.sh", "run"]