Commit dc98f18f authored by duanjinfei's avatar duanjinfei

update docker operate context time

parent bdd9c319
{ {
"nm_seed": "192.168.1.109:10001", "nm_seed": "43.198.252.255:10001",
"docker_server": "tcp://127.0.0.1:2375", "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, "node_manager_num": 1,
"heart_response": 30, "heart_response": 30,
"task_validator_time": 1, "task_validator_time": 1,
"container_num": 1, "container_num": 1,
"chain_id": 100, "chain_id": 100,
"validator_url": "192.168.1.109:20011" "validator_url": "43.198.252.255:20011"
} }
\ No newline at end of file
...@@ -109,7 +109,7 @@ func (d *DockerOp) ContainerIsRunning(containerId string) bool { ...@@ -109,7 +109,7 @@ func (d *DockerOp) ContainerIsRunning(containerId string) bool {
} }
func (d *DockerOp) ListContainer() []types.Container { func (d *DockerOp) ListContainer() []types.Container {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
defer cancel() defer cancel()
containers, err := d.dockerClient.ContainerList(ctx, types.ContainerListOptions{}) containers, err := d.dockerClient.ContainerList(ctx, types.ContainerListOptions{})
if err != nil { if err != nil {
...@@ -164,7 +164,7 @@ func (d *DockerOp) CreateAndStartContainer(imageName string, dockerCmd *models.D ...@@ -164,7 +164,7 @@ func (d *DockerOp) CreateAndStartContainer(imageName string, dockerCmd *models.D
} }
func (d *DockerOp) CreateContainer(imageName string, dockerCmd *models.DockerCmd) (string, error) { func (d *DockerOp) CreateContainer(imageName string, dockerCmd *models.DockerCmd) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
defer cancel() defer cancel()
portBinds := []nat.PortBinding{ portBinds := []nat.PortBinding{
{ {
...@@ -202,7 +202,7 @@ func (d *DockerOp) CreateContainer(imageName string, dockerCmd *models.DockerCmd ...@@ -202,7 +202,7 @@ func (d *DockerOp) CreateContainer(imageName string, dockerCmd *models.DockerCmd
} }
func (d *DockerOp) StartContainer(containerID string) bool { func (d *DockerOp) StartContainer(containerID string) bool {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
defer cancel() defer cancel()
// 启动容器 // 启动容器
if err := d.dockerClient.ContainerStart(ctx, containerID, types.ContainerStartOptions{}); err != nil { if err := d.dockerClient.ContainerStart(ctx, containerID, types.ContainerStartOptions{}); err != nil {
...@@ -215,7 +215,7 @@ func (d *DockerOp) StartContainer(containerID string) bool { ...@@ -215,7 +215,7 @@ func (d *DockerOp) StartContainer(containerID string) bool {
} }
func (d *DockerOp) StopContainer(containerID string) bool { func (d *DockerOp) StopContainer(containerID string) bool {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
defer cancel() defer cancel()
// 停止容器(如果正在运行) // 停止容器(如果正在运行)
if err := d.dockerClient.ContainerStop(ctx, containerID, container.StopOptions{}); err != nil { if err := d.dockerClient.ContainerStop(ctx, containerID, container.StopOptions{}); err != nil {
...@@ -238,7 +238,7 @@ func (d *DockerOp) StopAndDeleteContainer(containerID string) bool { ...@@ -238,7 +238,7 @@ func (d *DockerOp) StopAndDeleteContainer(containerID string) bool {
} }
func (d *DockerOp) RmContainer(containerID string) { func (d *DockerOp) RmContainer(containerID string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
defer cancel() defer cancel()
// 删除容器 // 删除容器
if err := d.dockerClient.ContainerRemove(ctx, containerID, types.ContainerRemoveOptions{}); err != nil { if err := d.dockerClient.ContainerRemove(ctx, containerID, types.ContainerRemoveOptions{}); err != nil {
...@@ -248,7 +248,7 @@ func (d *DockerOp) RmContainer(containerID string) { ...@@ -248,7 +248,7 @@ func (d *DockerOp) RmContainer(containerID string) {
} }
func (d *DockerOp) PsImages() ([]types.ImageSummary, error) { func (d *DockerOp) PsImages() ([]types.ImageSummary, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
defer cancel() defer cancel()
images, err := d.dockerClient.ImageList(ctx, types.ImageListOptions{}) images, err := d.dockerClient.ImageList(ctx, types.ImageListOptions{})
if err != nil { if err != nil {
...@@ -261,7 +261,7 @@ func (d *DockerOp) PsImages() ([]types.ImageSummary, error) { ...@@ -261,7 +261,7 @@ func (d *DockerOp) PsImages() ([]types.ImageSummary, error) {
} }
func (d *DockerOp) PsImageNameMap() (map[string]bool, error) { func (d *DockerOp) PsImageNameMap() (map[string]bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
defer cancel() defer cancel()
images, err := d.dockerClient.ImageList(ctx, types.ImageListOptions{}) images, err := d.dockerClient.ImageList(ctx, types.ImageListOptions{})
if err != nil { if err != nil {
...@@ -307,7 +307,7 @@ func (d *DockerOp) PullImage(info *models.ModelInfo) { ...@@ -307,7 +307,7 @@ func (d *DockerOp) PullImage(info *models.ModelInfo) {
} }
func (d *DockerOp) RmImage(imageId string) { func (d *DockerOp) RmImage(imageId string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
defer cancel() defer cancel()
// 删除镜像 // 删除镜像
_, err := d.dockerClient.ImageRemove(ctx, imageId, types.ImageRemoveOptions{}) _, err := d.dockerClient.ImageRemove(ctx, imageId, types.ImageRemoveOptions{})
...@@ -318,7 +318,7 @@ func (d *DockerOp) RmImage(imageId string) { ...@@ -318,7 +318,7 @@ func (d *DockerOp) RmImage(imageId string) {
} }
func (d *DockerOp) inspectContainer(containerId string) *types.ContainerJSON { func (d *DockerOp) inspectContainer(containerId string) *types.ContainerJSON {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
defer cancel() defer cancel()
// 容器信息 // 容器信息
containerJson, err := d.dockerClient.ContainerInspect(ctx, containerId) containerJson, err := d.dockerClient.ContainerInspect(ctx, containerId)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment