1. 程式人生 > >docker centos7創建consul鏡像以及用docker-compose啟動鏡像

docker centos7創建consul鏡像以及用docker-compose啟動鏡像

self. ids pan mmu roc gnu cer name agen

直接貼代碼了:

Dockfile:

# Version 0.1

FROM kuba_centos7

MAINTAINER kuba si812cn@163.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啟動鏡像