From e7e3746486e1f5fc1297176b645910b2934ab2c4 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Mon, 20 Apr 2026 14:46:24 +0800 Subject: [PATCH] fix docker_commands --- src/docker/docker_commands.erl | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/docker/docker_commands.erl b/src/docker/docker_commands.erl index 39149bf..7a1d4cd 100644 --- a/src/docker/docker_commands.erl +++ b/src/docker/docker_commands.erl @@ -36,8 +36,9 @@ check_image_exist(Image) when is_binary(Image) -> {ok, ContainerId :: binary()} | {error, Reason :: any()}. create_container(ContainerDir, #'ContainerDeployParams'{ container_name = ContainerName, - spec = Spec0 -}) when is_binary(ContainerName), is_list(ContainerDir), is_record(Spec0, 'ContainerSpec') -> + spec = Spec0 = #'ContainerSpec'{volumes = Volumes0} +}) when is_binary(ContainerName), is_list(ContainerDir) -> + Url = lists:flatten(io_lib:format("/containers/create?name=~s", [binary_to_list(ContainerName)])), %% 挂载预留的目录,用来作为配置文件的存放 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">>, read_only = false }, - Spec = Spec0#'ContainerSpec'{volumes = [ConfigVolume | Spec0#'ContainerSpec'.volumes]}, + Spec = Spec0#'ContainerSpec'{volumes = [ConfigVolume | Volumes0]}, Options = build_options(ContainerName, Spec), display_options(Options), @@ -239,20 +240,29 @@ inspect_container(ContainerId) when is_binary(ContainerId) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% 构建最终 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], #{ - <<"Image">> => to_binary(Spec#'ContainerSpec'.image), - <<"Cmd">> => [to_binary(Command) || Command <- Spec#'ContainerSpec'.command], - <<"Entrypoint">> => [to_binary(Entrypoint) || Entrypoint <- Spec#'ContainerSpec'.entrypoint], + <<"Image">> => to_binary(Image), + <<"Cmd">> => [to_binary(CommandItem) || CommandItem <- Command], + <<"Entrypoint">> => [to_binary(EntrypointItem) || EntrypointItem <- Entrypoint], <<"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), - <<"User">> => to_binary(Spec#'ContainerSpec'.user), - <<"WorkingDir">> => to_binary(Spec#'ContainerSpec'.working_dir), - <<"Hostname">> => to_binary(Spec#'ContainerSpec'.hostname), + <<"User">> => to_binary(User), + <<"WorkingDir">> => to_binary(WorkingDir), + <<"Hostname">> => to_binary(Hostname), <<"ExposedPorts">> => build_expose(Spec), <<"NetworkingConfig">> => build_networks(Spec), <<"Healthcheck">> => build_healthcheck(Spec),