1. docker update,主要是为了重新配置容器资源,比如内存,cpu等。
docker container update --restart=always 容器名字
2、直接改配置文件
首先停止容器,不然无法修改配置文件
配置文件路径为:/var/lib/docker/containers/容器ID
在该目录下找到一个文件 hostconfig.json ,找到该文件中关键字 RestartPolicy
修改前配置:"RestartPolicy":{"Name":"no","MaximumRetryCount":0}
修改后配置:"RestartPolicy":{"Name":"always","MaximumRetryCount":0}
最后启动容器。
3. 更新容易环境变量
修改-e参数变量:
docker run --name my-wordpress -e VIRTUAL_HOST=domain.com --link my-mysql:mysql -d spencercooley/wordpress
但是现在它已经运行了一段时间想在环境变量中添加另一个VIRTUAL_HOST.我不想删除容器,只更改VIRTUAL_HOST环境变量的值.
docker exec -i CONTAINER_ID /bin/bash -c "export VAR1=VAL1 && export VAR2=VAL2 && your_cmd"
或者:
进入到容器中docker exec -it containerId/Names /bin/bash,再使用export修改就可以了
export ENV='value'
4. 删除容器,重新配置参数初始化运行;
docker run -d --name kong1 \
-v /app/kong:/var/log/kong/ \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=192.168.214.59" \
-e "KONG_PG_PORT=5432" \
-e "KONG_PG_USER=postgres" \
-e "KONG_PG_POSSWORD=123456" \
-e "KONG_PG_DATABASE=kong" \
-e "KONG_PG_TIMEOUT=10000" \
-e "KONG_PROXY_ACCESS_LOG=/var/log/kong/proxy-access.log" \
-e "KONG_ADMIN_ACCESS_LOG=/var/log/kong/admin-access.log" \
-e "KONG_PROXY_ERROR_LOG=/var/log/kong/proxy-error.log" \
-e "KONG_ADMIN_ERROR_LOG=/var/log/kong/admin-error.log" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
-e "KONG_PROXY_LISTEN=0.0.0.0:8000, 0.0.0.0:8443 ssl" \
-p 80:8000 -p 443:8443 -p 8001:8001 -p 8444:8444 \
--restart=always kong:1.4.0rc1