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

What does href=# mean in a link?

Links to the current page. ------------------- Com...

Brief analysis of MySQL union and union all

In the database, both UNION and UNION ALL keyword...

MySQL 5.7.23 installation and configuration method graphic tutorial

This article records the installation tutorial of...

An enhanced screenshot and sharing tool for Linux: ScreenCloud

ScreenCloud is a great little app you didn’t even...

Thoughts on copy_{to, from}_user() in the Linux kernel

Table of contents 1. What is copy_{to,from}_user(...

How to implement the @person function through Vue

This article uses vue, and adds mouse click event...

HTML table tag tutorial (3): width and height attributes WIDTH, HEIGHT

By default, the width and height of the table are...

Detailed explanation of Nginx status monitoring and log analysis

1. Nginx status monitoring Nginx provides a built...

Implementation code for adding slash to Vue element header

<template> <div class="app-containe...

Building command line applications with JavaScript

Table of contents 1. Install node 2. Install Comm...

JavaScript to dynamically load and delete tables

This article shares the specific code of JavaScri...

Exploring the Linux Kernel: The Secrets of Kconfig

Get a deep understanding of how the Linux configu...

Solution to 1449 and 1045 exceptions when connecting to MySQL

Solution to 1449 and 1045 exceptions when connect...