fix: 解决容器编辑时端口冲突的问题 (#1615)

This commit is contained in:
ssongliu 2023-07-12 14:33:19 +08:00 committed by GitHub
parent 66007c07e2
commit 1a891cb048
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 5 deletions

View file

@ -7,6 +7,7 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"
@ -421,15 +422,17 @@ func (u *ContainerService) ContainerUpdate(req dto.ContainerOperate) error {
global.LOG.Errorf("force pull image %s failed, err: %v", req.Image, err)
}
}
if err := client.ContainerRemove(ctx, req.ContainerID, types.ContainerRemoveOptions{Force: true}); err != nil {
return err
}
config := oldContainer.Config
hostConf := oldContainer.HostConfig
var networkConf network.NetworkingConfig
if err := loadConfigInfo(req, config, hostConf, &networkConf); err != nil {
return err
}
if err := client.ContainerRemove(ctx, req.ContainerID, types.ContainerRemoveOptions{Force: true}); err != nil {
return err
}
global.LOG.Infof("new container info %s has been update, now start to recreate", req.Name)
container, err := client.ContainerCreate(ctx, config, hostConf, &networkConf, &v1.Platform{}, req.Name)
@ -540,6 +543,11 @@ func (u *ContainerService) ContainerLogClean(req dto.OperationWithName) error {
return err
}
_, _ = file.Seek(0, 0)
files, _ := filepath.Glob(fmt.Sprintf("%s.*", container.LogPath))
for _, file := range files {
_ = os.Remove(file)
}
return nil
}

View file

@ -148,10 +148,16 @@ func loadNetIO() {
if net2.BytesSent != 0 && net1.BytesSent != 0 {
itemNet.Up = float64(net2.BytesSent-net1.BytesSent) / 1024 / 60
}
if itemNet.Up > 100000000 {
global.LOG.Errorf("net2: %v, net1: %v, BytesSent: %v \n", net2.BytesSent, net1.BytesSent, float64(net2.BytesSent-net1.BytesSent)/1024/60)
}
if net2.BytesRecv != 0 && net1.BytesRecv != 0 {
itemNet.Down = float64(net2.BytesRecv-net1.BytesRecv) / 1024 / 60
}
if itemNet.Down > 100000000 {
global.LOG.Errorf("net2: %v, net1: %v, BytesRecv: %v \n", net2.BytesRecv, net1.BytesRecv, float64(net2.BytesRecv-net1.BytesRecv)/1024/60)
}
netList = append(netList, itemNet)
break
}

View file

@ -92,7 +92,7 @@ const timeOptions = ref([
]);
const searchLogs = async () => {
if (!Number(logSearch.tail) || Number(logSearch.tail) <= 0) {
if (!Number(logSearch.tail) || Number(logSearch.tail) < 0) {
MsgError(i18n.global.t('container.linesHelper'));
return;
}

View file

@ -47,6 +47,7 @@ const acceptParams = async (params: DialogProps): Promise<void> => {
}
if (!checkIp(res.data.systemIP)) {
window.open(`http://${res.data.systemIP}:${params.port}`, '_blank');
return;
}
window.open(`http://[${res.data.systemIP}]:${params.port}`, '_blank');
};

View file

@ -134,7 +134,7 @@ watch(logVisiable, (val) => {
if (screenfull.isEnabled && !val && !mobile.value) screenfull.exit();
});
const searchLogs = async () => {
if (!Number(logSearch.tail) || Number(logSearch.tail) <= 0) {
if (!Number(logSearch.tail) || Number(logSearch.tail) < 0) {
MsgError(i18n.global.t('container.linesHelper'));
return;
}