docker容器时指定了command,后期要修改可通过修改对应容器的config.v2.json来配置
import os, json
####################################################################################
# Options that must be configured
# docker container name
# The data type is string, example:
# name = 'HelloApp'
name = 'HelloApp'
# The command to execute when the docker container starts
# The data type is list, example:
# command = [u'python', u'/codes/HelloApp/index.py']
command = [u'python', u'/codes/HelloApp/index.py']
# Disk location of docker container
# The data type is string, example:
# docker_container_path = '/var/lib/docker/containers'
docker_container_path = '/var/lib/docker/containers'
####################################################################################
# The following parts should not be changed at will !!!!!!!!!!!!
#
# get docker container id
result = os.popen("docker ps --no-trunc|grep %s" % name)
res = result.read()
if res:
id_arr = res.split(' ')
if len(id_arr) > 2:
container_id = id_arr[0]
if container_id:
# format config.v2.json path
config_path = docker_container_path + "/%s/config.v2.json" % container_id
if os.path.exists(config_path):
with open(config_path, 'r') as fr:
config = json.loads(fr.read())
if config:
# stop docker service
os.system("systemctl stop docker.socket")
os.system("systemctl stop docker")
# modfiy config
config[u'Args'] = command
config[u'Config'][u'Cmd'] = [u'nohup'] + command
# write to config file
with open(config_path, 'w') as fw:
fw.write(json.dumps(config))
# start docker service
os.system("systemctl start docker")
####################################################################################
# END



