Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
power-node
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
power-node
Commits
dc98f18f
Commit
dc98f18f
authored
Feb 04, 2024
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update docker operate context time
parent
bdd9c319
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
12 deletions
+12
-12
config.json
config.json
+3
-3
docker.go
operate/docker.go
+9
-9
No files found.
config.json
View file @
dc98f18f
{
"nm_seed"
:
"
192.168.1.109
:10001"
,
"nm_seed"
:
"
43.198.252.255
:10001"
,
"docker_server"
:
"tcp://127.0.0.1:2375"
,
"api_url"
:
"http://
192.168.1.8
:8087/api/task/taskheat"
,
"api_url"
:
"http://
43.198.252.255
:8087/api/task/taskheat"
,
"node_manager_num"
:
1
,
"heart_response"
:
30
,
"task_validator_time"
:
1
,
"container_num"
:
1
,
"chain_id"
:
100
,
"validator_url"
:
"
192.168.1.109
:20011"
"validator_url"
:
"
43.198.252.255
:20011"
}
\ No newline at end of file
operate/docker.go
View file @
dc98f18f
...
...
@@ -109,7 +109,7 @@ func (d *DockerOp) ContainerIsRunning(containerId string) bool {
}
func
(
d
*
DockerOp
)
ListContainer
()
[]
types
.
Container
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
0
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
*
2
0
)
defer
cancel
()
containers
,
err
:=
d
.
dockerClient
.
ContainerList
(
ctx
,
types
.
ContainerListOptions
{})
if
err
!=
nil
{
...
...
@@ -164,7 +164,7 @@ func (d *DockerOp) CreateAndStartContainer(imageName string, dockerCmd *models.D
}
func
(
d
*
DockerOp
)
CreateContainer
(
imageName
string
,
dockerCmd
*
models
.
DockerCmd
)
(
string
,
error
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
0
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
*
2
0
)
defer
cancel
()
portBinds
:=
[]
nat
.
PortBinding
{
{
...
...
@@ -202,7 +202,7 @@ func (d *DockerOp) CreateContainer(imageName string, dockerCmd *models.DockerCmd
}
func
(
d
*
DockerOp
)
StartContainer
(
containerID
string
)
bool
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
0
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
*
2
0
)
defer
cancel
()
// 启动容器
if
err
:=
d
.
dockerClient
.
ContainerStart
(
ctx
,
containerID
,
types
.
ContainerStartOptions
{});
err
!=
nil
{
...
...
@@ -215,7 +215,7 @@ func (d *DockerOp) StartContainer(containerID string) bool {
}
func
(
d
*
DockerOp
)
StopContainer
(
containerID
string
)
bool
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
0
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
*
2
0
)
defer
cancel
()
// 停止容器(如果正在运行)
if
err
:=
d
.
dockerClient
.
ContainerStop
(
ctx
,
containerID
,
container
.
StopOptions
{});
err
!=
nil
{
...
...
@@ -238,7 +238,7 @@ func (d *DockerOp) StopAndDeleteContainer(containerID string) bool {
}
func
(
d
*
DockerOp
)
RmContainer
(
containerID
string
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
0
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
*
2
0
)
defer
cancel
()
// 删除容器
if
err
:=
d
.
dockerClient
.
ContainerRemove
(
ctx
,
containerID
,
types
.
ContainerRemoveOptions
{});
err
!=
nil
{
...
...
@@ -248,7 +248,7 @@ func (d *DockerOp) RmContainer(containerID string) {
}
func
(
d
*
DockerOp
)
PsImages
()
([]
types
.
ImageSummary
,
error
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
0
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
*
2
0
)
defer
cancel
()
images
,
err
:=
d
.
dockerClient
.
ImageList
(
ctx
,
types
.
ImageListOptions
{})
if
err
!=
nil
{
...
...
@@ -261,7 +261,7 @@ func (d *DockerOp) PsImages() ([]types.ImageSummary, error) {
}
func
(
d
*
DockerOp
)
PsImageNameMap
()
(
map
[
string
]
bool
,
error
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
0
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
*
2
0
)
defer
cancel
()
images
,
err
:=
d
.
dockerClient
.
ImageList
(
ctx
,
types
.
ImageListOptions
{})
if
err
!=
nil
{
...
...
@@ -307,7 +307,7 @@ func (d *DockerOp) PullImage(info *models.ModelInfo) {
}
func
(
d
*
DockerOp
)
RmImage
(
imageId
string
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
0
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
*
2
0
)
defer
cancel
()
// 删除镜像
_
,
err
:=
d
.
dockerClient
.
ImageRemove
(
ctx
,
imageId
,
types
.
ImageRemoveOptions
{})
...
...
@@ -318,7 +318,7 @@ func (d *DockerOp) RmImage(imageId string) {
}
func
(
d
*
DockerOp
)
inspectContainer
(
containerId
string
)
*
types
.
ContainerJSON
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
1
0
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
*
2
0
)
defer
cancel
()
// 容器信息
containerJson
,
err
:=
d
.
dockerClient
.
ContainerInspect
(
ctx
,
containerId
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment