docker centos7创建consul镜像以及用docker-compose启动镜像

Posted si812cn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker centos7创建consul镜像以及用docker-compose启动镜像相关的知识,希望对你有一定的参考价值。

直接贴代码了:

Dockfile:

# Version 0.1

FROM kuba_centos7

MAINTAINER kuba [email protected].com

# This is the release of Consul to pull in.
ENV CONSUL_VERSION=1.4.0
# This is the location of the releases.
ENV HASHICORP_RELEASES=https://releases.hashicorp.com

# Create a consul user and group first so the IDs get set the same way, even as
# the rest of this may change over time.

# Set up certificates, base tools, and Consul.

RUN yum -y install ca-certificates gnupg libcap iputils  && yum clean all  && export CC=/opt/rh/devtoolset-6/root/usr/bin/gcc  && export CXX=/opt/rh/devtoolset-6/root/usr/bin/g++  && groupadd consul  && useradd -r -g consul consul -s /bin/false  && mkdir -p /opt/software  && cd /opt/software/  
 && gpg --keyserver pgp.mit.edu --recv-keys 91A6E7F85D05C65630BEF18951852D87348FFC4C  && wget ${HASHICORP_RELEASES}/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip  && wget ${HASHICORP_RELEASES}/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_SHA256SUMS  && wget ${HASHICORP_RELEASES}/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_SHA256SUMS.sig  && gpg --batch --verify consul_${CONSUL_VERSION}_SHA256SUMS.sig consul_${CONSUL_VERSION}_SHA256SUMS  && grep consul_${CONSUL_VERSION}_linux_amd64.zip consul_${CONSUL_VERSION}_SHA256SUMS | sha256sum -c  && mkdir /usr/local/consul  && unzip -o consul_${CONSUL_VERSION}_linux_amd64.zip -d /usr/local/bin  && consul --version  && mkdir -p /consul/data  && mkdir -p /consul/config  && chown -R consul:consul /consul  && echo ‘hosts: files dns‘ > /etc/nsswitch.conf

# Expose the consul data directory as a volume since there‘s mutable state in there.
VOLUME /consul/data

# Server RPC is used for communication between Consul clients and servers for internal
# request forwarding.

EXPOSE 8300

# Serf LAN and WAN (WAN is used only by Consul servers) are used for gossip between
# Consul agents. LAN is within the datacenter and WAN is between just the Consul
# servers in all datacenters.
EXPOSE 8301 8301/udp 8302 8302/udp

# HTTP and DNS (both TCP and UDP) are the primary interfaces that applications
# use to interact with Consul.
EXPOSE 8500 8600 8600/udp

# Consul doesn‘t need root privileges so we run it as the consul user from the
# entry point script. The entry point script also uses dumb-init as the top-level
# process to reap any zombie processes created by Consul sub-processes.
ENTRYPOINT [consul]

# By default you‘ll get an insecure single-node development server that stores
# everything in RAM, exposes a web UI and HTTP endpoints, and bootstraps itself.
# Don‘t use this configuration for production.
CMD ["agent", "-dev", "-client", "0.0.0.0"]

docker build -t kuba_consul140 ./

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

创建docker-compose文件

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: ‘2‘

services:
  consul140_0:
    image: kuba_consul140
    restart: always
    container_name: consul140_0
    volumes:
        - ./data/:/consul/data/
    ports:
      - 8300:8300
      - 8301:8301
      - 8301:8301/udp
      - 8302:8302
      - 8302:8302/udp
      - 8500:8500
      - 8600:8600
      - 8600:8600/udp 
	entrypoint: consul
    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启动镜像的主要内容,如果未能解决你的问题,请参考以下文章

Docker应用系列| 构建Consul集群

consul配置的导出导入(consul跑在docker里的方式)

docker compose与consul

docker compose与consul

CentOS7下安装配置Docker | 并创建镜像提交到DockerHub

Consul docker集群