直接贴代码了:

Dockfile:

  1. # Version 0.1
  2.  
  3. FROM kuba_centos7
  4.  
  5. MAINTAINER kuba si812cn@163.com
  6.  
  7. # This is the release of Consul to pull in.
  8. ENV CONSUL_VERSION=1.4.0
  9. # This is the location of the releases.
  10. ENV HASHICORP_RELEASES=https://releases.hashicorp.com
  11.  
  12. # Create a consul user and group first so the IDs get set the same way, even as
  13. # the rest of this may change over time.
  14.  
  15. # Set up certificates, base tools, and Consul.
  16.  
  17. RUN yum -y install ca-certificates gnupg libcap iputils \
  18. && yum clean all \
  19. && export CC=/opt/rh/devtoolset-6/root/usr/bin/gcc \
  20. && export CXX=/opt/rh/devtoolset-6/root/usr/bin/g++ \
  21. && groupadd consul \
  22. && useradd -r -g consul consul -s /bin/false \
  23. && mkdir -p /opt/software \
  24. && cd /opt/software/ \
  25. && gpg --keyserver pgp.mit.edu --recv-keys 91A6E7F85D05C65630BEF18951852D87348FFC4C \
  26. && wget ${HASHICORP_RELEASES}/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip \
  27. && wget ${HASHICORP_RELEASES}/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_SHA256SUMS \
  28. && wget ${HASHICORP_RELEASES}/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_SHA256SUMS.sig \
  29. && gpg --batch --verify consul_${CONSUL_VERSION}_SHA256SUMS.sig consul_${CONSUL_VERSION}_SHA256SUMS \
  30. && grep consul_${CONSUL_VERSION}_linux_amd64.zip consul_${CONSUL_VERSION}_SHA256SUMS | sha256sum -c \
  31. && mkdir /usr/local/consul \
  32. && unzip -o consul_${CONSUL_VERSION}_linux_amd64.zip -d /usr/local/bin \
  33. && consul --version \
  34. && mkdir -p /consul/data \
  35. && mkdir -p /consul/config \
  36. && chown -R consul:consul /consul \
  37. && echo 'hosts: files dns' > /etc/nsswitch.conf
  38.  
  39. # Expose the consul data directory as a volume since there's mutable state in there.
  40. VOLUME /consul/data
  41.  
  42. # Server RPC is used for communication between Consul clients and servers for internal
  43. # request forwarding.
  44.  
  45. EXPOSE 8300
  46.  
  47. # Serf LAN and WAN (WAN is used only by Consul servers) are used for gossip between
  48. # Consul agents. LAN is within the datacenter and WAN is between just the Consul
  49. # servers in all datacenters.
  50. EXPOSE 8301 8301/udp 8302 8302/udp
  51.  
  52. # HTTP and DNS (both TCP and UDP) are the primary interfaces that applications
  53. # use to interact with Consul.
  54. EXPOSE 8500 8600 8600/udp
  55.  
  56. # Consul doesn't need root privileges so we run it as the consul user from the
  57. # entry point script. The entry point script also uses dumb-init as the top-level
  58. # process to reap any zombie processes created by Consul sub-processes.
  59. ENTRYPOINT [consul]
  60.  
  61. # By default you'll get an insecure single-node development server that stores
  62. # everything in RAM, exposes a web UI and HTTP endpoints, and bootstraps itself.
  63. # Don't use this configuration for production.
  64. CMD ["agent", "-dev", "-client", "0.0.0.0"]

docker build -t kuba_consul140 ./

中间如果失败,一般是网络问题,隔断时间重新执行一次就好

创建docker-compose文件

  1. # Copyright IBM Corp. All Rights Reserved.
  2. #
  3. # SPDX-License-Identifier: Apache-2.0
  4. #
  5.  
  6. version: '2'
  7.  
  8. services:
  9. consul140_0:
  10. image: kuba_consul140
  11. restart: always
  12. container_name: consul140_0
  13. volumes:
  14. - ./data/:/consul/data/
  15. ports:
  16. - 8300:8300
  17. - 8301:8301
  18. - 8301:8301/udp
  19. - 8302:8302
  20. - 8302:8302/udp
  21. - 8500:8500
  22. - 8600:8600
  23. - 8600:8600/udp
  24. entrypoint: consul
  25. command: agent -server -data-dir=/consul/data -config-dir=/consul/config -bootstrap -node=consul1140_0 -client=0.0.0.0

启动镜像:

docker-compose -f docker-compose-consul.yaml up -d 2>&1

查看镜像是否启动成功:

docker ps

查看consul

docker exec -t xxxx容器编号  consul members

docker centos7创建consul镜像以及用docker-compose启动镜像的更多相关文章

  1. Centos7创建支持ssh服务的docker镜像

    如何在centos7中使用docker创建一个支持ssh连接的容器 1.拉取centos7.4镜像(由于7.4目前是最稳定的版本,所以推荐使用centos7.4) docker pull centos ...

  2. centos7创建docker tomcat镜像

    1 准备宿主系统 准备一个 CentOS 7操作系统,具体要求如下: 必须是 64 位操作系统 建议内核在 3.8 以上 通过以下命令查看您的 CentOS 内核: 1 # uname -r 2 安装 ...

  3. docker Dockerfile 创建镜像

    Docker 组件 1. docker client : docker的客户端 2. docker server : docker daemon的主要组成部分,接受用户通过docker client发 ...

  4. Centos7 创建本地 docker 仓库极其遇到的问题

    环境安装: VirtualBox 安装 Centos7 安装 docker 1. 配置私有仓库和客户端地址 私有仓库:192.168.1.104 客户端:192.168.1.103 通过 Centos ...

  5. Docker 创建镜像、修改、上传镜像

    Docker 创建镜像.修改.上传镜像 –创建镜像有很多方法,用户可以从 Docker Hub 获取已有镜像并更新,也可以利用本地文件系统创建一个. 一.创建镜像 创建镜像有很多方法,用户可以从 Do ...

  6. docker——Dockerfile创建镜像

    写在前面: 继续docker的学习,昨天用docker成功跑了tomcat,但是在centos中镜像跑的容器手动装jdk和tomcat,今天学习用Dockerfile创建镜像,并在上面搭建java环境 ...

  7. 转 docker创建私有仓库和k8s中使用私有镜像

    docker私有仓库建立 环境说明我们选取192.168.5.2做私有仓库地址yum install docker -y1.启动docker仓库端口服务 docker run -d -p 5000:5 ...

  8. Docker(十一)-Docker commit创建镜像

    创建镜像有很多方法,用户可以从 Docker Hub 获取已有镜像并更新,也可以利用本地文件系统创建一个. 修改已有的镜像 查看已有的镜像: $ sudo docker images REPOSITO ...

  9. 两种方式创建支持SSH服务的docker镜像

    方法一:基于commit命令创建 1.首先,从docker的源中查看我们需要的镜像,本案例中使用Ubuntu作为基础镜像. # federico @ linux in ~ [16:57:38] $ s ...

随机推荐

  1. 5种网络IO模型(有图,很清楚)

    同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到底有什么区别?这个问题其实不同的人给出 ...

  2. RobotFramework--环境安装1

    1.RobotFramework RobotFramework 的架构是一个通用型的验收测试和验收测试驱动开发的自动化测试框架(ATDD).它 具有易于使用的表格来组织测试过程和测试数据. 3.1版本 ...

  3. input输入框只能输入正整数

    <input type="text" value="1" onkeyup="if(this.value.length==1){this.valu ...

  4. .net core部署到Ubuntu碰到的问题

    数据库连接的时候,会报错“MySql.Data.MySqlClient.MySqlException:“The host localhost does not support SSL connecti ...

  5. 001——使用composer安装ThinkPHP5

    composer create-project topthink/think tp5 --prefer-dist

  6. ansible批量管理工具的搭建与简单的操作

    ansible的安装 # [root@localhost ~]# cat /etc/redhat-release CentOS Linux release (Core) [root@localhost ...

  7. python读取与写入csv,txt格式文件

    python读取与写入csv,txt格式文件 在数据分析中经常需要从csv格式的文件中存取数据以及将数据写书到csv文件中.将csv文件中的数据直接读取为dict类型和DataFrame是非常方便也很 ...

  8. 第八节 多态和Object类

    多态的定义:某一类事物的多种存在形态 例子:学生类:包含学生A和学生B 学生A对象对应的类型是学生A类型:StudentA studentA = new StudentA; Student stude ...

  9. Linux shell基础知识(上)

    Linux shell基础知识(上) 目录 一.shell介绍 二.命令历史 三.命令补全和别名 四.通配符 五.输入输出重定向 六.管道符和作业控制 七.shell变量 八.环境变量配置文件 九.b ...

  10. SQLserver触发器实现A表insert到B表

    CREATE TABLE tab1(tab1_id varchar(11));CREATE TABLE tab2(tab2_id varchar(11)); 现在我们有两张表,要实现在A表里面inse ...