Docker uses a single image to map to multiple ports

Docker uses a single image to map to multiple ports

need:

The official website's resource server certainly cannot use one instance, it needs multiple instances together, but if it continues to copy it is too slow, I wonder if I can directly use the docker image to create several identical container instances.

Two docker-compose.yml files

version: '3'
services:
 micro-hcnet-website-13:
  image: 172.18.0.1:5000/hcnet-website-12:0.0.1-SNAPSHOT
  restart: on-failure
  ports:
  -8311:8211
~
version: '3'
services:
 micro-hcnet-website-13:
  image: 172.18.0.1:5000/hcnet-website-12:0.0.1-SNAPSHOT
  restart: on-failure
  ports:
  -8211:8211
~

After executing docker-compse.yml

Display normal startup

View Container

Mapping success

Finally check consul

Sure enough, they are all the same mapping interface.

Additional knowledge: Getting started with Docker - Building multiple containers (docker-compose)

Starting multiple services (containers) at a time will facilitate our operations in production practice

Take haproy load balancing apache service and nginx service as an example

Multi-container application of docker through compose

Compose is a Docker application that allows users to define and run multiple containers. In Compose you can use YAML files to configure your application services. Then, with just one simple command, all the services you configured are created and started.

Using Compose basically involves the following three steps:

Define your application environment in a Dockerfile to make it replicable anywhere.

Define the services that make up your application in docker-compose.yml so that they can run together in isolated environments.

Finally, run docker-compose up and Compose will start and run the entire application.

1. Edit the docker-compose.yml file to specify multiple images

apache: # apache service image: rhel7:v1 # parent image name expose:
        - 80 # Expose port volumes: # Mount volume - ./web/:/var/www/html

nginx: # nginx serviceimage: nginx # parent imageexpose:    
        - 80 # Expose port haproxy: # haproxy service image: haproxy # Parent image volumes: # Mount volume - ./haproxy:/usr/local/etc/haproxy
    links: # Associated container - apache
        - nginx
    ports: #Port mapping - "8080:80"
    expose: # Exposed service port - 80

2. Edit the haproxy configuration file

global # Global configuration, log information log 127.0.0.1 local0
    log 127.0.0.1 local1 notice
defaults
    log global
    option httplog
    option dontlognull
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms
    stats uri /status
frontend balancer
    bind 0.0.0.0:80 # Listening port default_backend web_backends # Default backend backend web_backends
    Balance Round Robin
    server weba apache:80 check # The backend a apache corresponds to the content in the links in the .yml file server webb nginx:80 check

Check whether the required documents are sufficient

[root@foundation21 compose]# ls
docker-compose.yml haproxy web
[root@foundation21 compose]# pwd
/tmp/docker/compose
# View file affiliation [root@foundation21 compose]# tree
.
├── docker-compose.yml
├── haproxy
│ └── haproxy.cfg
└── web
  └── index.html

2 directories, 3 files

Execute the docker-compose up command in the cmopose directory to start multiple images at the same time

To view it in a browser:

haproxy implements load balancing for backend web servers

The above Docker uses a single image to map to multiple ports. This is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker file storage path, modify port mapping operation mode
  • Docker primary network port mapping configuration
  • How to modify the port mapping of a running Docker container
  • How to dynamically modify container port mapping in Docker
  • Docker port mapping and external inaccessibility issues
  • Troubleshooting process for Docker container suddenly failing to connect after port mapping
  • Add port mapping after docker container starts
  • Docker enables multiple port mapping commands

<<:  Detailed Analysis of the Selection of MySQL Common Index and Unique Index

>>:  The solution of html2canvas that pictures cannot be captured normally

Recommend

5 Tips for Protecting Your MySQL Data Warehouse

Aggregating data from various sources allows the ...

Detailed explanation of Vue custom instructions

Table of contents Vue custom directive Custom dir...

Summary of MySQL slow log practice

Slow log query function The main function of slow...

How to use cc.follow for camera tracking in CocosCreator

Cocos Creator version: 2.3.4 Demo download: https...

WeChat applet to obtain mobile phone number step record

Preface Recently, I encountered such a problem wh...

JS realizes the card dealing animation

This article example shares the specific code of ...

A simple example of MySQL joint table query

MySql uses joined table queries, which may be dif...

How to convert a string into a number in JavaScript

Table of contents 1.parseInt(string, radix) 2. Nu...

Summary of H5 wake-up APP implementation methods and points for attention

Table of contents Preface Jump to APP method URL ...

A detailed discussion on detail analysis in web design

In design work, I often hear designers participati...

A brief introduction to the usage of decimal type in MySQL

The floating-point types supported in MySQL are F...

In-depth explanation of Vue multi-select list component

A Multi-Select is a UI element that lists all opt...

React encapsulates the global bullet box method

This article example shares the specific code of ...