fix docker_commands
This commit is contained in:
parent
576ccb2b10
commit
e7e3746486
@ -36,8 +36,9 @@ check_image_exist(Image) when is_binary(Image) ->
|
|||||||
{ok, ContainerId :: binary()} | {error, Reason :: any()}.
|
{ok, ContainerId :: binary()} | {error, Reason :: any()}.
|
||||||
create_container(ContainerDir, #'ContainerDeployParams'{
|
create_container(ContainerDir, #'ContainerDeployParams'{
|
||||||
container_name = ContainerName,
|
container_name = ContainerName,
|
||||||
spec = Spec0
|
spec = Spec0 = #'ContainerSpec'{volumes = Volumes0}
|
||||||
}) when is_binary(ContainerName), is_list(ContainerDir), is_record(Spec0, 'ContainerSpec') ->
|
}) when is_binary(ContainerName), is_list(ContainerDir) ->
|
||||||
|
|
||||||
Url = lists:flatten(io_lib:format("/containers/create?name=~s", [binary_to_list(ContainerName)])),
|
Url = lists:flatten(io_lib:format("/containers/create?name=~s", [binary_to_list(ContainerName)])),
|
||||||
%% 挂载预留的目录,用来作为配置文件的存放
|
%% 挂载预留的目录,用来作为配置文件的存放
|
||||||
ConfigFile = list_to_binary(docker_helper:get_config_file(ContainerDir)),
|
ConfigFile = list_to_binary(docker_helper:get_config_file(ContainerDir)),
|
||||||
@ -46,7 +47,7 @@ create_container(ContainerDir, #'ContainerDeployParams'{
|
|||||||
container_path = <<"/usr/local/etc/service.conf">>,
|
container_path = <<"/usr/local/etc/service.conf">>,
|
||||||
read_only = false
|
read_only = false
|
||||||
},
|
},
|
||||||
Spec = Spec0#'ContainerSpec'{volumes = [ConfigVolume | Spec0#'ContainerSpec'.volumes]},
|
Spec = Spec0#'ContainerSpec'{volumes = [ConfigVolume | Volumes0]},
|
||||||
Options = build_options(ContainerName, Spec),
|
Options = build_options(ContainerName, Spec),
|
||||||
display_options(Options),
|
display_options(Options),
|
||||||
|
|
||||||
@ -239,20 +240,29 @@ inspect_container(ContainerId) when is_binary(ContainerId) ->
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
%% 构建最终 JSON Map
|
%% 构建最终 JSON Map
|
||||||
build_options(ContainerName, #'ContainerSpec'{} = Spec) when is_binary(ContainerName) ->
|
build_options(ContainerName, Spec = #'ContainerSpec'{
|
||||||
|
image = Image,
|
||||||
|
command = Command,
|
||||||
|
entrypoint = Entrypoint,
|
||||||
|
env = Env,
|
||||||
|
labels = Labels,
|
||||||
|
user = User,
|
||||||
|
working_dir = WorkingDir,
|
||||||
|
hostname = Hostname
|
||||||
|
}) when is_binary(ContainerName) ->
|
||||||
%% 容器名称作为环境变量,注入到运行时环境中
|
%% 容器名称作为环境变量,注入到运行时环境中
|
||||||
Envs0 = [to_binary(Env) || Env <- Spec#'ContainerSpec'.env],
|
Envs0 = [to_binary(EnvItem) || EnvItem <- Env],
|
||||||
Envs = [<<"CONTAINER_NAME=", ContainerName/binary>>|Envs0],
|
Envs = [<<"CONTAINER_NAME=", ContainerName/binary>>|Envs0],
|
||||||
#{
|
#{
|
||||||
<<"Image">> => to_binary(Spec#'ContainerSpec'.image),
|
<<"Image">> => to_binary(Image),
|
||||||
<<"Cmd">> => [to_binary(Command) || Command <- Spec#'ContainerSpec'.command],
|
<<"Cmd">> => [to_binary(CommandItem) || CommandItem <- Command],
|
||||||
<<"Entrypoint">> => [to_binary(Entrypoint) || Entrypoint <- Spec#'ContainerSpec'.entrypoint],
|
<<"Entrypoint">> => [to_binary(EntrypointItem) || EntrypointItem <- Entrypoint],
|
||||||
<<"Env">> => Envs,
|
<<"Env">> => Envs,
|
||||||
<<"Labels">> => maps:from_list([{to_binary(Key), to_binary(Value)} || {Key, Value} <- Spec#'ContainerSpec'.labels]),
|
<<"Labels">> => maps:from_list([{to_binary(Key), to_binary(Value)} || {Key, Value} <- Labels]),
|
||||||
<<"Volumes">> => build_volumes(Spec),
|
<<"Volumes">> => build_volumes(Spec),
|
||||||
<<"User">> => to_binary(Spec#'ContainerSpec'.user),
|
<<"User">> => to_binary(User),
|
||||||
<<"WorkingDir">> => to_binary(Spec#'ContainerSpec'.working_dir),
|
<<"WorkingDir">> => to_binary(WorkingDir),
|
||||||
<<"Hostname">> => to_binary(Spec#'ContainerSpec'.hostname),
|
<<"Hostname">> => to_binary(Hostname),
|
||||||
<<"ExposedPorts">> => build_expose(Spec),
|
<<"ExposedPorts">> => build_expose(Spec),
|
||||||
<<"NetworkingConfig">> => build_networks(Spec),
|
<<"NetworkingConfig">> => build_networks(Spec),
|
||||||
<<"Healthcheck">> => build_healthcheck(Spec),
|
<<"Healthcheck">> => build_healthcheck(Spec),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user