Author Archives: Robins

.Net Core 5.0 Upload File limit via Swagger Api report error: error: request entity too large [Three Methods]

.Net Core 5.0 The size of the uploaded file through the Swagger Api is limited, report the error: error: request entity too large

 

Solution:

1. Add the following code in Startup

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<FormOptions>(options =>
    {
        // Set the limit to 256 MB
        options.MultipartBodyLengthLimit = 268435456;
    });
}

2. Add in Program

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.ConfigureKestrel((context, options) =>
            {
                // Handle requests up to 50 MB
                options.Limits.MaxRequestBodySize = 52428800;
            })
            .UseStartup<Startup>();
        });

3. Add the method of adding features in the operation method

// Handle requests up to 50 MB
[RequestSizeLimit(52428800)]
public ActionResult<ResultDto<bool>> AddFile()
{
    ...
}

Personally recommend the first one, and limit the case to the configuration file.

[Solved] UnsatisfiedDependencyException: Error creating bean with name

Error message:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘com.xubo.mybatisplus.MyBatisPlusTest’: Unsatisfied dependency expressed through field ‘userMapper’; of type ‘com.xubo.mybatisplus.mapper.UserMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

problem causes:

This is because mapperscan is not added to the startup class; the corresponding class cannot be scanned.
Add @MapperScan(“com…*.dao”) to the startup class; the problem is solved!

My own actual problem is to add it, but what I wrote is the path of the specific class, with the class name, so it doesn’t work, you must write the package name. Change it to the package name and start querying data successfully.

@MapperScan function : specify the package where the interface to be implemented class is located, and then all interfaces under the package will generate corresponding implementation classes after compilation
Add location: add above the Springboot startup class

The following paragraph is what I saw when I searched, and I don’t know its correctness. For more than an hour, I inadvertently researched that the location of the springboot startup class, in addition to the first principle, only scans the annotations of the same level directory and subdirectory where it is located, and at the same time the startup class is separated from the directory java by at least two layers of packages.

image-20221201211430383

How to Solve “parcel segmentation fault” Error in Linux

parcel is a very good all-in-one simple tool, which can facilitate web construction, because no problems were found when using mac to build, but when running on linux, it was
found that there was a problem, a segmentation fault occurred, and I tried a few times. There are various solutions (upgrade npm, node, yarn version) but none of them are solved, and try to use
strace information as follows

rt_sigprocmask( SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask( SIG_SETMASK, ~[ RTMIN RT_1], [], 8) = 0
read( 4, "*", 1)                          = 1
rt_sigaction( SIGIO, { sa_handler = SIG_DFL, sa_mask =[], sa_flags = SA_RESTORER, sa_restorer = 0x7eff95e58630}, NULL, 8) = 0
write( 5, "*", 1)                         = 1
rt_sigprocmask( SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask( SIG_SETMASK, ~[ RTMIN RT_1], [], 8) = 0
read( 4, "*", 1)                          = 1
rt_sigaction( SIGPWR, { sa_handler = SIG_DFL, sa_mask =[], sa_flags = SA_RESTORER, sa_restorer = 0x7eff95e58630}, NULL, 8) = 0
write( 5, "*", 1)                         = 1
rt_sigprocmask( SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask( SIG_SETMASK, ~[ RTMIN RT_1], [], 8) = 0
read( 4, "*", 1)                          = 1
rt_sigaction( SIGSTKFLT, { sa_handler = SIG_DFL, sa_mask =[], sa_flags = SA_RESTORER, sa_restorer = 0x7eff95e58630}, NULL, 8) = 0
write( 5, "*", 1)                         = 1
rt_sigprocmask( SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask( SIG_SETMASK, ~[ RTMIN RT_1], [], 8) = 0
read( 4, "*", 1)                          = 1
rt_sigaction( SIGSYS, { sa_handler = SIG_DFL, sa_mask =[], sa_flags = SA_RESTORER, sa_restorer = 0x7eff95e58630}, NULL, 8) = 0
write( 5, "*", 1)                         = 1
rt_sigprocmask( SIG_SETMASK, [], NULL, 8) = 0
write( 17, "", 0)                         = 0
futex( 0x306c80c, FUTEX_CMP_REQUEUE_PRIVATE, 1, 2147483647, 0x306c7e0, 100) = 4
write( 12, "\1\0\0\0\0\0\0\0", 8)         = 8
futex( 0x7eff95a7a9d0, FUTEX_WAIT, 30173, NULL) = - 1 EAGAIN ( Resource temporarily unavailable)
munmap( 0x7eff9527a000, 8392704)          = 0
epoll_ctl( 3, EPOLL_CTL_ADD, 6, { EPOLLIN, { u32 = 6, u64 = 6 } } ) = 0
epoll_ctl( 3, EPOLL_CTL_ADD, 8, { EPOLLIN, { u32 = 8, u64 = 8 } } ) = 0
epoll_wait( 3, [], 1024, 0)               = 0
close( 6)                                 = 0
close( 7)                                 = 0
close( 8)                                 = 0
close( 3)                                 = 0
fstat( 0, { st_mode = S_IFCHR | 0620, st_rdev = makedev( 136, 0), ...}) = 0
fcntl( 0, F_GETFL)                        = 0x8002 ( flags O_RDWR | O_LARGEFILE)
rt_sigprocmask( SIG_BLOCK, [ TTOU], NULL, 8) = 0
ioctl( 0, SNDCTL_TMR_START or TCSETS, { B38400 opost isig icanon echo ...}) = 0
ioctl( 0, TCGETS, { B38400 opost isig icanon echo ... }) = 0
rt_sigprocmask( SIG_UNBLOCK, [ TTOU], NULL, 8) = 0
fstat( 1, { st_mode = S_IFCHR | 0620, st_rdev = makedev( 136, 0), ...}) = 0
fcntl( 1, F_GETFL)                        = 0x8002 ( flags O_RDWR | O_LARGEFILE)
rt_sigprocmask( SIG_BLOCK, [ TTOU], NULL, 8) = 0
ioctl( 1, SNDCTL_TMR_START or TCSETS, { B38400 opost isig icanon echo ...}) = 0
ioctl( 1, TCGETS, { B38400 opost isig icanon echo ... }) = 0
rt_sigprocmask( SIG_UNBLOCK, [ TTOU], NULL, 8) = 0
fstat( 2, { st_mode = S_IFCHR | 0620, st_rdev = makedev( 136, 0), ...}) = 0
fcntl( 2, F_GETFL)                        = 0x8002 ( flags O_RDWR | O_LARGEFILE)
rt_sigprocmask( SIG_BLOCK, [ TTOU], NULL, 8) = 0
ioctl( 2, SNDCTL_TMR_START or TCSETS, { B38400 opost isig icanon echo ...}) = 0
ioctl( 2, TCGETS, { B38400 opost isig icanon echo ... }) = 0
rt_sigprocmask( SIG_UNBLOCK, [ TTOU], NULL, 8) = 0
close( 4)                                 = 0
close( 5)                                 = 0
# There will be exception information here
futex( 0x2c97aa4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x2c97aa0, FUTEX_OP_SET << 28 | 0 << 12 | FUTEX_OP_CMP_GT << 24 | 0x1) = 1
futex( 0x2c97a60, FUTEX_WAKE_PRIVATE, 1) = 1
futex( 0x7eff8effd9d0, FUTEX_WAIT, 30179, NULL) = 0
munmap( 0x7eff94a79000, 8392704)          = 0
munmap( 0x7eff94278000, 8392704)          = 0
munmap( 0x7eff8f7ff000, 8392704)          = 0
munmap( 0x7eff8effe000, 8392704)          = 0
exit_group( 0)                            = ?
+++ exited with 0 +++

The discovery is not very clear, and the trace information of perf is used as follows

1340.638 ( 43.568 ms): node / 30376   ... [ continued]: futex()) = 0
  1384.214 ( 0.008 ms): node / 30376 futex( uaddr: 0x2c97aa4, op: WAKE_OP | PRIV, val: 1, utime: 0x1, uaddr2: 0x2c97aa0, val3: 0x4000001d) = 1
  1384.226 ( 0.003 ms): node / 30376 futex( uaddr: 0x2c97a60, op: WAKE | PRIV, val: 1 ) = 0
  1384.236 ( 0.009 ms): node / 30376 madvise( start: 0x7f096e8db000, len_in: 8368128, behavior: MADV_DONTNEED) = 0
  1384.249( ): node / 30376 exit( )
  1340.722 ( 43.609 ms): node / 30378   ... [ continued]: futex()) = 0
  1384.337 ( 0.006 ms): node / 30378 futex( uaddr: 0x2c97aa4, op: WAKE_OP | PRIV, val: 1, utime: 0x1, uaddr2: 0x2c97aa0, val3: 0x4000001d) = 1
  1384.346 ( 0.003 ms): node / 30378 futex( uaddr: 0x2c97a60, op: WAKE | PRIV, val: 1 ) = 0
  1384.354 ( 0.007 ms): node / 30378 madvise( start: 0x7f096d8d9000, len_in: 8368128, behavior: MADV_DONTNEED) = 0
  1384.364( ): node / 30378 exit( )
  1341.178 ( 43.235 ms): node / 30377   ... [ continued]: futex()) = 0
  1384.417 ( 0.012 ms): node / 30377 futex( uaddr: 0x2c97aa4, op: WAKE_OP | PRIV, val: 1, utime: 0x1, uaddr2: 0x2c97aa0, val3: 0x4000001d) = 1
  1384.432 ( 0.003 ms): node / 30377 futex( uaddr: 0x2c97a60, op: WAKE | PRIV, val: 1 ) = 0
  1384.439 ( 0.005 ms): node / 30377 madvise( start: 0x7f096e0da000, len_in: 8368128, behavior: MADV_DONTNEED) = 0
  1384.447( ): node / 30377 exit( )
   307.570 ( 1077.301 ms): node / 30373   ... [ continued]: futex()) = - 1 ( unknown) INTERNAL ERROR: strerror_r( 512, [ buf], 128) = 22
         ? ( ​​): node / 30355   ... [ continued]: epoll_wait()) = 1
  1402.290 ( 0.004 ms): node / 30355 read( fd: 12, buf: 0x7fc200eaa8d0, count: 1024 ) = 8
  1402.305 ( 0.003 ms ): node / 30355 close( fd: 10 ) = 0
  1402.314 ( 0.002 ms): node / 30355 close( fd: 11 ) = 0
  1402.324 ( 0.002 ms): node / 30355 close( fd: 12) = 0
  1402.331 ( 0.002 ms ): node / 30355 close( fd: 9 ) = 0
  1402.341 ( 0.007 ms): node / 30355 madvise( start: 0x7fc2006ae000, len_in: 8368128, behavior: MADV_DONTNEED) = 0
  1402.351( ): node / 30355 exit( )
   281.999 ( 1121.739 ms): node / 30362   ... [ continued]: futex()) = 0
  1403.750 ( 0.008 ms): node / 30362 futex( uaddr: 0x2c97aa4, op: WAKE_OP | PRIV, val: 1, utime: 0x1, uaddr2: 0x2c97aa0, val3: 0x4000001d) = 1
  1403.760 ( 0.002 ms): node / 30362 futex( uaddr: 0x2c97a60, op: WAKE | PRIV, val: 1 ) = 0
  1403.766 ( 0.004 ms): node / 30362 madvise( start: 0x7fc1f8ffa000, len_in: 8368128, behavior: MADV_DONTNEED) = 0
  1403.772( ): node / 30362 exit( )
   282.093 ( 1121.731 ms): node / 30364   ... [ continued]: futex()) = 0
  1403.831 ( 0.009 ms): node / 30364 futex( uaddr: 0x2c97aa4, op: WAKE_OP | PRIV, val: 1, utime: 0x1, uaddr2: 0x2c97aa0, val3: 0x4000001d) = 1
  1403.842 ( 0.002 ms): node / 30364 futex( uaddr: 0x2c97a60, op: WAKE | PRIV, val: 1 ) = 0
  1403.846 ( 0.004 ms): node / 30364 madvise( start: 0x7fc1eb7ff000, len_in: 8368128, behavior: MADV_DONTNEED) = 0
  1403.852( ): node / 30364 exit( )
    13.769 ( 1390.637 ms): node / 30360   ... [ continued]: futex()) = - 1 ( unknown) INTERNAL ERROR: strerror_r( 512, [ buf], 128) = 22

I saw some things but I am still not sure how to solve it. Then I searched the github issue and found a lot of similar problems. From the description, the source-map plugin is related to the integration of rust

Solution

Very simple, the temporary solution is to add environment variables PARCEL_WORKER_BACKEND=processThe problem is temporarily solved, rust is good, but there is also a problem with rust and external integration (
many extensions of parcel use rust extensions)

References

https://github.com/parcel-bundler/parcel/issues/7598
https://github.com/parcel-bundler/source-map/pull/91

Android: How to Add Background Music for Activity with Service

Create a new Service and name it MyFirstBgmServic

package com.example.cyberwoodenfish;

import android.app.Service;
 import android.content.Intent;
 import android.media.MediaPlayer;
 import android.os.Binder;
 import android.os.IBinder;

public  class MyFirstBgmService extends Service {
     public MyFirstBgmService() {
    }
    
    MediaPlayer mp;

    @Override
    public  void onCreate() {                   // call 
        super .onCreate() when starting the service;
        mp = MediaPlayer.create( this ,R.raw.dabeizhou);
        mp.start();
    }

    @Override
    public  void onDestroy() {                 // Stop music playback when the service is destroyed 
        if (mp != null ){
            mp.stop();
            mp.release();
        }
        super.onDestroy ();
    }

    @Override
    public IBinder onBind(Intent intent) {
         // TODO: Return the communication channel to the service. 
        throw  new UnsupportedOperationException("Not yet implemented" );
    }
}

Then start package com.example.cyberwoodenfish in MainActivity ;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.content.Intent;
 import android.media.AudioManager;
 import android.media.SoundPool;
 import android.os.Bundle;
 import android.view.View;
 import android.view.animation.Animation;
 import android.view.animation.AnimationUtils;
 import android.widget.ImageButton;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 import android.widget.Toast;

public  class MainActivity extends Activity {
    
    @Override
    protected  void onCreate(Bundle savedInstanceState) {
         super .onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intentbgm;
        intentbgm = new Intent(MainActivity.this , MyFirstBgmService.class ) ;
        startService(intentbgm);       //. . . Code unrelated to bgm was eaten by me again

    }
}

Docker: How to Enter the Closed Container and View the Logging

During the development process, especially when debugging the code, there will always be a situation where the Dockerfile or application exception causes the application to fail to start.
At this point, you want to go inside the container and see what’s going on.
At this time, I want to use docker exec -it Container_name bash it to enter the container normally, but Error response from daemon: Container baa1e5…… is not runningan exception will occur.

solution

View the container ID that needs to be entered

# View all container processes
docker ps -a 
# Copy the ID of this unbootable container
baa1e5

Save the abnormally started container as an image

# Here is a random mirror name
docker commit baa1e5 temp/test

Start a new container to view the log of the startup process

docker run -it temp/test sh

Python: How to Costomize the Background of PS

Here is the example code on how to modify the PS background.

Nedd to Install  photoshop-python-api
 
 1 """Change the color of the background and foreground."""
 2 # Import local modules
 3 from photoshop import Session
 4 
 5 
 6 with Session() as ps:
 7     foregroundColor = ps.SolidColor()
 8     foregroundColor.rgb.red = 255
 9     foregroundColor.rgb.green = 0
10     foregroundColor.rgb.blue = 0
11     ps.app.foregroundColor = foregroundColor
12 
13     backgroundColor = ps.SolidColor()
14     backgroundColor.rgb.red = 0
15     backgroundColor.rgb.green = 0
16     backgroundColor.rgb.blue = 0
17     ps.app.backgroundColor = backgroundColor

[Solved] Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are “development”, “test”, and “production”. Instead, received: undefined.

Running webpack gives the following error:

 

 The reason for the bug is:

The environment variable is not configured properly. Although the mode: ‘development’ configuration item is configured in webpack.dev.js, this environment variable is the environment variable for code running, not the environment variable for babel running, so it needs to be defined.

solution:

// Download cross-env. A library dedicated to defining environment variables 
npm install --save-dev cross- env

// Add the configuration in front of the webpage running command 
in package.json
 "scripts" : {
     "start": "npm run dev" ,
     "dev": " cross-env NODE_ENV=development webpack serve --config ./config /webpack.dev.js" 
 },

git submodule add Error: SSL certificate problem unable to get local issuer certificate

Errors encountered when using hugo and installing themesSSL certificate problem: unable to get local issuer certificate

(base) PS E:\vscodeProject\chz8bit.github.io\quickstart> git submodule add https://github.com/nanxiaobei/hugo-paper themes/paper
Cloning into 'E:/vscodeProject/chz8bit.github.io/quickstart/themes/paper'...
fatal: unable to access 'https://github.com/nanxiaobei/hugo-paper/': SSL certificate problem: unable to get local issuer certificate
fatal: clone of 'https://github.com/nanxiaobei/hugo-paper' into submodule path 'E:/vscodeProject/chz8bit.github.io/quickstart/themes/paper' failed

 

Solved the problem with the following link
How do I configure Git to trust certificates from the Windows Certificate Store? – Stack Overflow
Cant clone from GitHub : SSL certificate problem: unable to get local issuer certificate Issue #9293 desktop/desktop
Personally, I think it is mainly this line of code, and there is a corresponding explanation https://github.com/desktop/desktop/issues/9293#issuecomment-607357181

git config --global http.sslBackend schannel

The last run was successful

(base) PS E:\vscodeProject\chz8bit.github.io\quickstart> git submodule add https://github.com/nanxiaobei/hugo-paper themes/paper
Cloning into 'E:/vscodeProject/chz8bit.github.io/quickstart/themes/paper'...
remote: Enumerating objects: 1594, done.
remote: Counting objects: 100% (731/731), done.
remote: Compressing objects: 100% (402/402), done.
remote: Total 1594 (delta 361), reused 404 (delta 327), pack-reused 863 eceiving objects: 100% (1594/1594), 5.46 MiB | 445.00 KiB/s
Receiving objects: 100% (1594/1594), 5.50 MiB | 368.00 KiB/s, done.
Resolving deltas: 100% (750/750), done.
starting fsmonitor-daemon in 'E:/vscodeProject/chz8bit.github.io/quickstart/themes/paper'

 

Vue: How to Share Your Screen

Document: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia

Method: https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API/Using_Screen_Capture

Example Codes:

<template>

  <video ref="video" autoplay="true" style="width: 500px; height: 300px"></video>
  <canvas ref="canvas" style="display: none"></canvas>

</template>
 


<script lang="ts" setup>


 import { onMounted, ref } from 'vue'

  const canvas = ref()
  const video = ref()
  const timer = ref()
 



 onMounted(async () => {
let stream = null
try {
    stream = await navigator.mediaDevices.getDisplayMedia({
        video: true,
        audio: true
    })
    video.value.srcObject = stream
    dumpOptionsInfo()
    const ctx = canvas.value.getContext('2d')
    // devicePixelRatio returns the ratio of the physical pixel resolution of the current display device to the CSS pixel resolution, allowing for better reproduction of realistic video scenes
    const ratio = window.devicePixelRatio || 1
    ctx.scale(ratio, ratio)
    // The canvas size remains the same as the image size, and the screenshot is not redundant
    canvas.value.width = video.value.offsetWidth * ratio
    canvas.value.height = video.value.offsetHeight * ratio
    timer.value = setInterval(() = > {
        ctx.drawImage(video.value, 0, 0, canvas.value.width, canvas.value.height)
        const imgUrl = canvas.value.toDataURL('image/jpeg')
        console.log('imgUrl: ', imgUrl)
    }, 5000)
} catch (e) {
    console.log(e)
}
// Monitor to manually turn off screen sharing
const videoTrack = video.value.srcObject.getVideoTracks()[0]
videoTrack.addEventListener('ended', handleStop)
  })

const dumpOptionsInfo = () = > {
    const videoTrack = video.value.srcObject.getVideoTracks()[0]
    console.info('Track settings:')
    console.info(JSON.stringify(videoTrack.getSettings(), null, 2))
    console.info('Track constraints:')
    console.info(JSON.stringify(videoTrack.getConstraints(), null, 2))
}
const handleStop = () = > {
    clearInterval(timer.value)
    let tracks = video.value.srcObject.getTracks()
    tracks.forEach((track: {
        stop: () = > any
    }) = > track.stop())
    video.value.srcObject = null
}

 

luffy: How to create a database and interface

1 Create a Banner database

Since the time, deletion, etc. in this database can be shared, we can write a separate table model for him, and finally make it not built into the database when the database is built. This code can be shared, and then we inherit BaseModels

from django.db import models


class BaseModels(models.Model):
    created_time = models.DateTimeField(auto_now_add=True, verbose_name= ' created time ' )
    updated_time = models.DateTimeField(auto_now=True, verbose_name= ' last update time ' )
    is_delete = models.BooleanField(default=False, verbose_name= ' Delete or not ' )
    is_show = models.BooleanField(default=True, verbose_name= ' Whether it is on the shelf ' )
    orders = models.IntegerField(verbose_name= ' priority ' )

    class Meta:
        abstract = True
from utils.models import BaseModels
 from django.db import models

class Banner(BaseModels):
    title = models.CharField(max_length=16, unique=True, verbose_name= ' name ' )
    image = models.ImageField(upload_to= ' banner ' , verbose_name= ' image ' )
    link = models.CharField(max_length=64, verbose_name= ' jump link ' )
    info = models.TextField(verbose_name= ' details ' )

    class Meta:
        db_table = ' luffy_banner ' 
        verbose_name_plural = ' Carousel chart '

    def  __str__ (self):
         return self.title

At this point, our Banner table is created

2 Write the Banner interface

By inheriting GenericViewSet and ListModelMixin, we can quickly write the interface, but if we want to return data in a specified format, we must pass the list data to another variable from the list method in ListModelMixin, so that we can easily Pass the value according to the specified parameters of the function. Since this list method may be reused in many places, we can make a package for it.

from rest_framework.mixins import ListModelMixin
 from .response import APIResponse

class BannerListView(ListModelMixin):
     def list(self, request, *args, ** kwargs):
        res = super().list(request, *args, ** kwargs)
         return APIResponse(data=res.data)
from luffyapi.utils.listviews import BannerListView
 from .models import Banner
 from .serializer import BannerSerializers
 # Create your views here. 
from rest_framework.viewsets import GenericViewSet
 from django.conf import settings

class BannerView(GenericViewSet, BannerListView):
    queryset =Banner.objects.all().filter(is_delete=False,is_show=True).order_by( ' orders ' )[:settings.AREA]
    serializer_class =BannerSerializers

Android: How to get the size of font you set (Example Code)

Here is an example code to get the size of your font on Android

 

Example Codes:

procedure TForm10.Button1Click(Sender: TObject);
var
  Configuration: JConfiguration;
  CurrentNightMode: Integer;
begin
  Configuration := TAndroidHelper.Context.GetResources.getConfiguration;

  Text1.Text:=Configuration.fontScale.ToString;

end;
1
uses Androidapi.JNI.GraphicsContentViewText, Androidapi.Helpers

Docker: How to Modify Your Hostname

docker change hostname

When docker is running, it is the same as the container id, and the host name is randomly generated. If you want to fix the host name, I will summarize several common methods.

specify hostname

When docker run, specify the hostname parameter, this parameter will directly write the corresponding hostname to the /etc/hostname file of the machine

docker run -itd --network $netname --hostname $host --name $name yourimage

Specify other machine information

You can also add hostname: use the add-host=$hostname:$ip parameter, which will add a line of mapping to the /etc/hostname file in the container

docker run -itd --network $netname --add-host=$host:$ip --name $name yourimage

If it is through docker-compose, you need to pass the extra_hosts parameter

# docker-compose.yml
extra_hosts:
 - "host1:172.18.0.3"
 - "host2:172.18.0.4"

If deployed through k8s