🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] # 1. 安装Docker **1. 卸载旧版本** ```shell yum list installed | grep docker yum -y remove docker的包名称 --删除docker的所有镜像和容器 rm -rf /var/lib/docker ``` **2. 安装必要的软件包** ```shell yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 ``` **3. 设置下载的镜像仓库** ```shell yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo ``` **4. 列出有哪些docker版本** ```shell # yum list docker-ce --showduplicates | sort -r docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable ``` **5. 安装指定版本(这里使用18.06.3.ce-3.el7版本)** ```shell yum install docker-ce-18.06.3.ce ``` **6. 查看版本** ```shell # docker -v Docker version 18.06.3-ce, build d7080c1 ``` **7. 启动Docker** ```shell # systemctl start docker # systemctl enable docker # systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) ``` **8. 添加阿里云镜像下载地址** ```shell # vim /etc/docker/daemon.json { "registry-mirrors": ["https://zydiol88.mirror.aliyuncs.com"] } ``` **9. 重启Docker** ```shell # systemctl restart docker # systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) ``` <br/> # 2. 使用Dockerfile制作微服务镜像 下面演示利用Dockerfile制作一个Eureka注册中心的镜像。 <br/> **1. 上传 tensquare-eureka-server-1.0-SNAPSHOT.jar 包到 production-server 机器上** **2. 编写`Dockerfile`文件** ```dockerfile # vim Dockerfile FROM openjdk:8-jdk-alpine ARG JAR_FILE COPY ${JAR_FILE} /target/tensquare-eureka-server-1.0-SNAPSHOT.jar EXPOSE 10086 ENTRYPOINT ["java","-jar","/target/tensquare-eureka-server-1.0-SNAPSHOT.jar"] ``` **3. 构建镜像** ```shell docker build --build-arg JAR_FILE=tensquare-eureka-server-1.0-SNAPSHOT.jar -t tensquare-eureka-server:v1.0 . ``` **4. 查看镜像是否构建成功** ```shell # docker images REPOSITORY TAG IMAGE ID CREATED SIZE tensquare-eureka-server v1.0 70b977ee0289 35 seconds ago 150MB ``` **5. 创建容器** ```shell docker run -i --name=tensquare-eureka-server -p 10086:10086 tensquare-eureka-server:v1.0 ``` **6. 浏览器访问容器:http://192.168.1.30:10086/**