Idein / dockworker

Docker daemon API client in Rust
61 stars 35 forks source link

support log_config #131

Closed cutsea110 closed 2 years ago

cutsea110 commented 2 years ago

I'd like to use .HostConfig.LogConfig on ContainerCreateOptions. ref. ) https://docs.docker.com/engine/api/v1.41/#tag/Container/operation/ContainerCreate

Once this is merged, the log identifier can be controlled by setting the tag. ref.) https://docs.docker.com/config/containers/logging/log_tags/

cutsea110 commented 2 years ago

I modify example/create-container.rs like below.

extern crate dockworker;

use dockworker::{ContainerCreateOptions, ContainerHostConfig, Docker, LogConfig, LogConfigType};

fn main() {
    let docker = Docker::connect_with_defaults().unwrap();
    let mut create = ContainerCreateOptions::new("localstack/localstack");
    let mut host_config = ContainerHostConfig::default();
    let mut log_config = LogConfig::new(LogConfigType::Journald);
    log_config
        .config
        .insert("tag".to_string(), "MyAppId".to_string());
    host_config.log_config(log_config);
    create.host_config(host_config);
    let container = docker.create_container(Some("testing"), &create).unwrap();
    println!("{:?}", container)
}

and then I got my expected journal log.

11月 04 15:12:00 waikiki MyAppId(42)[1018]: Waiting for all LocalStack services to be ready
11月 04 15:12:00 waikiki MyAppId(42)[1018]: 2022-11-04 06:12:00,623 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
11月 04 15:12:00 waikiki MyAppId(42)[1018]: 2022-11-04 06:12:00,624 INFO supervisord started with pid 16
11月 04 15:12:01 waikiki connmand[475]: docker0 {RX} 304 packets 36763 bytes
11月 04 15:12:01 waikiki connmand[475]: docker0 {TX} 414 packets 118598 bytes
11月 04 15:12:01 waikiki connmand[475]: docker0 {newlink} index 3 address 02:42:B5:1C:74:FB mtu 1500
11月 04 15:12:01 waikiki connmand[475]: docker0 {newlink} index 3 operstate 6 <UP>
11月 04 15:12:01 waikiki MyAppId(42)[1018]: 2022-11-04 06:12:01,629 INFO spawned: 'infra' with pid 21
11月 04 15:12:02 waikiki avahi-daemon[443]: Joining mDNS multicast group on interface veth4130e90.IPv6 with address fe80::44af:72ff:fe53:1667.
11月 04 15:12:02 waikiki avahi-daemon[443]: New relevant interface veth4130e90.IPv6 for mDNS.
11月 04 15:12:02 waikiki avahi-daemon[443]: Registering new address record for fe80::44af:72ff:fe53:1667 on veth4130e90.*.
11月 04 15:12:02 waikiki MyAppId(42)[1018]: 2022-11-04 06:12:02,632 INFO success: infra entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
11月 04 15:12:02 waikiki MyAppId(42)[1018]:
11月 04 15:12:02 waikiki MyAppId(42)[1018]: LocalStack version: 1.2.1.dev
11月 04 15:12:02 waikiki MyAppId(42)[1018]: LocalStack build date: 2022-11-03
11月 04 15:12:02 waikiki MyAppId(42)[1018]: LocalStack build git hash: e14d6270
11月 04 15:12:02 waikiki MyAppId(42)[1018]:
11月 04 15:12:07 waikiki MyAppId(42)[1018]: Waiting for all LocalStack services to be ready
11月 04 15:12:08 waikiki MyAppId(42)[1018]: 2022-11-04T06:12:08.207  WARN --- [-functhread5] hypercorn.error            : ASGI Framework Lifespan error, continuing without Lifespan support
11月 04 15:12:08 waikiki MyAppId(42)[1018]: 2022-11-04T06:12:08.207  WARN --- [-functhread5] hypercorn.error            : ASGI Framework Lifespan error, continuing without Lifespan support
11月 04 15:12:08 waikiki MyAppId(42)[1018]: 2022-11-04T06:12:08.208  INFO --- [-functhread5] hypercorn.error            : Running on https://0.0.0.0:4566 (CTRL + C to quit)
11月 04 15:12:08 waikiki MyAppId(42)[1018]: 2022-11-04T06:12:08.208  INFO --- [-functhread5] hypercorn.error            : Running on https://0.0.0.0:4566 (CTRL + C to quit)
11月 04 15:12:08 waikiki MyAppId(42)[1018]: 2022-11-04T06:12:08.411  INFO --- [  MainThread] localstack.utils.bootstrap : Execution of "start_runtime_components" took 5423.82ms
11月 04 15:12:08 waikiki MyAppId(42)[1018]: Ready.
11月 04 15:12:15 waikiki connmand[475]: veth4130e90 {newlink} index 22 address 46:AF:72:53:16:67 mtu 1500
11月 04 15:12:15 waikiki connmand[475]: veth4130e90 {newlink} index 22 operstate 6 <UP>
11月 04 15:12:17 waikiki MyAppId(42)[1018]: Sending -15 to supervisord
11月 04 15:12:18 waikiki MyAppId(42)[1018]: 2022-11-04 06:12:18,449 WARN received SIGTERM indicating exit request
11月 04 15:12:18 waikiki MyAppId(42)[1018]: 2022-11-04 06:12:18,450 INFO waiting for infra to die
11月 04 15:12:19 waikiki MyAppId(42)[1018]: 2022-11-04 06:12:19,843 INFO stopped: infra (exit status 0)
11月 04 15:12:19 waikiki systemd[1]: docker-e3c2bd606dac2f78f05190e34a53ff128bbbb726335076c504f21e7d3357cd5b.scope: Deactivated successfully.
11月 04 15:12:19 waikiki systemd[1]: docker-e3c2bd606dac2f78f05190e34a53ff128bbbb726335076c504f21e7d3357cd5b.scope: Consumed 2.200s CPU time.
11月 04 15:12:19 waikiki containerd[575]: time="2022-11-04T15:12:19.889746962+09:00" level=info msg="shim disconnected" id=e3c2bd606dac2f78f05190e34a53ff128bbbb726335076c504f21e7d3357cd5b
11月 04 15:12:19 waikiki dockerd[1018]: time="2022-11-04T15:12:19.889784677+09:00" level=info msg="ignoring event" container=e3c2bd606dac2f78f05190e34a53ff128bbbb726335076c504f21e7d3357cd5b module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
11月 04 15:12:19 waikiki containerd[575]: time="2022-11-04T15:12:19.890315995+09:00" level=warning msg="cleaning up after shim disconnected" id=e3c2bd606dac2f78f05190e34a53ff128bbbb726335076c504f21e7d3357cd5b namespace=moby
11月 04 15:12:19 waikiki containerd[575]: time="2022-11-04T15:12:19.890337394+09:00" level=info msg="cleaning up dead shim"
11月 04 15:12:19 waikiki containerd[575]: time="2022-11-04T15:12:19.898655446+09:00" level=warning msg="cleanup warnings time=\"2022-11-04T15:12:19+09:00\" level=info msg=\"starting signal loop\" namespace=moby pid=19662 runtime=io.containerd.runc.v2\n"