%%%------------------------------------------------------------------- %%% @author anlicheng %%% @copyright (C) 2025, %%% @doc %%% %%% @end %%% Created : 23. 9月 2025 17:23 %%%------------------------------------------------------------------- -module(docker_commands_tests). -author("anlicheng"). %% API -export([test_pull/0, test_commands/0, test_create_container/0]). test_pull() -> Image = <<"docker.1ms.run/library/nginx:latest">>, docker_commands:pull_image(Image, fun(Msg) -> logger:debug("msg is: ~p", [Msg]) end). test_commands() -> Id = <<"redpanda-console">>, StopRes = docker_commands:stop_container(Id), logger:debug("stop res: ~p", [StopRes]), StartRes = docker_commands:start_container(Id), logger:debug("start res: ~p", [StartRes]). test_create_container() -> M = #{ <<"image">> => <<"docker.1ms.run/library/nginx:latest">>, <<"container_name">> => <<"my_nginx_new1">>, <<"command">> => [ <<"nginx">>, <<"-g">>, <<"daemon off;">> ], <<"entrypoint">> => [ <<"/docker-entrypoint.sh">> ], <<"envs">> => [ <<"ENV1=val1">>, <<"ENV2=val2">> ], <<"env_file">> => [ <<"./env.list">> ], <<"ports">> => [ <<"8080:80">>, <<"443:443">> ], <<"expose">> => [ <<"80">>, <<"443">> ], <<"volumes">> => [ <<"/host/data:/data">>, <<"/host/log:/var/log">> ], <<"networks">> => [ <<"mynet">> ], <<"labels">> => #{ <<"role">> => <<"web">>, <<"env">> => <<"prod">> }, <<"restart">> => <<"always">>, <<"user">> => <<"www-data">>, <<"working_dir">> => <<"/app">>, <<"hostname">> => <<"myhost">>, <<"privileged">> => true, <<"cap_add">> => [ <<"NET_ADMIN">> ], <<"cap_drop">> => [ <<"MKNOD">> ], <<"devices">> => [ <<"/dev/snd:/dev/snd">> ], <<"mem_limit">> => <<"512m">>, <<"mem_reservation">> => <<"256m">>, <<"cpu_shares">> => 512, <<"cpus">> => 1.5, <<"ulimits">> => #{ <<"nofile">> => <<"1024:2048">> }, <<"sysctls">> => #{ <<"net.ipv4.ip_forward">> => <<"1">> }, <<"tmpfs">> => [ <<"/tmp">> ], <<"extra_hosts">> => [ <<"host1:192.168.0.1">> ], <<"healthcheck">> => #{ <<"test">> => [ <<"CMD-SHELL">>, <<"curl -f http://localhost || exit 1">> ], <<"interval">> => <<"30s">>, <<"timeout">> => <<"10s">>, <<"retries">> => 3 } }, docker_commands:create_container(<<"my_nginx_xx3">>, "/usr/local/code/efka/", M).