Docker compose kasutamine

Allikas: Imre kasutab arvutit
Redaktsioon seisuga 6. juuli 2026, kell 10:02 kasutajalt Imre (arutelu | kaastöö) (→‎Kasulikud lisamaterjalid)
Mine navigeerimisribaleMine otsikasti

Sissejuhatus

TODO

Tööpõhimõte

TODO

Käsundamine

Isikliku võrgu jms ressurssidega konteineri tekitamine

# cat docker-compose-nginx.yml 
services:
  svc_nginx:
    image: nginx:latest

    environment:
      - TZ=Europe/Tallinn

    ports:
     - "8011:80"
 
    container_name: cn_nginx
   
    volumes:
      - /srv/nginx/volume/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro

    networks:
      - nw_nginx
     
networks:
  nw_nginx:
    name: nw_nginx
    driver: bridge

kus

  • tundub, et uuemal ajal ei ole asjakohane compose failis kasutada rida 'version: xxx'

Kasutamiseks sobib öelda

$ docker compose -f docker-compose-nginx.yml up
[+] Running 2/2
 ✔ Network nw_nginx    Created   0.1s 
 ✔ Container cn_nginx  Created   0.1s 
Attaching to cn_nginx
dc_nginx  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
dc_nginx  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
dc_nginx  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
...

Ning tulemusena on moodustunud sellised ressursid

$ docker network ls
NETWORK ID     NAME                   DRIVER    SCOPE
3fe6d3988e37   bridge                 bridge    local
617b4a0d5de5   host                   host      local
d4743d12eb6a   none                   null      local
67a9effbfa9b   nw_nginx               bridge    local

ning

# docker container ls
CONTAINER ID   IMAGE             COMMAND                  CREATED          STATUS        PORTS                     NAMES
78a420d0f791   nginx:latest      "/docker-entrypoint.…"   43 minutes ago   Up 1 second   0.0.0.0:8011->80/tcp      cn_nginx

Konteineri ja võrgu kustutamiseks sobib öelda

$ docker compose -f docker-compose-nginx.yml down
[+] Running 2/2
 ✔ Container cn_nginx  Removed    0.3s 
 ✔ Network nw_nginx    Removed    0.1s

Logimine

Konteineri sees

root@dh-post:~# docker exec -ti 53 bash

root@5346ca828019:/# ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.1  14884  7608 ?        Ss   Jul05   0:00 nginx: master process nginx -g daemon off;
nginx         29  0.0  0.0  15340  3516 ?        S    Jul05   0:00 nginx: worker process
nginx         30  0.0  0.0  15340  3516 ?        S    Jul05   0:00 nginx: worker process
nginx         31  0.0  0.0  15340  3516 ?        S    Jul05   0:00 nginx: worker process
nginx         32  0.0  0.0  15340  3516 ?        S    Jul05   0:00 nginx: worker process
root         253  0.0  0.0   4320  3844 pts/0    Ss+  Jul05   0:00 bash
root         280  0.9  0.0   4320  3692 pts/2    Ss   09:59   0:00 bash
root         286  0.0  0.0   6388  3760 pts/2    R+   09:59   0:00 ps aux

root@5346ca828019:/# lsof -p 1 -P -n
COMMAND PID USER  FD   TYPE             DEVICE SIZE/OFF     NODE NAME
nginx     1 root cwd    DIR               0,68       38  3528403 /
nginx     1 root rtd    DIR               0,68       38  3528403 /
nginx     1 root txt    REG               0,68  1683584  3126357 /usr/sbin/nginx
nginx     1 root mem    REG               0,41           3126357 /usr/sbin/nginx (path dev=0,68)
nginx     1 root mem    REG               0,41           3123196 /usr/lib/x86_64-linux-gnu/libzstd.so.1.5.7 (path dev=0,68)
nginx     1 root mem    REG               0,41           3123113 /usr/lib/x86_64-linux-gnu/libc.so.6 (path dev=0,68)
nginx     1 root mem    REG               0,41           3123194 /usr/lib/x86_64-linux-gnu/libz.so.1.3.1 (path dev=0,68)
nginx     1 root mem    REG               0,41           3123121 /usr/lib/x86_64-linux-gnu/libcrypto.so.3 (path dev=0,68)
nginx     1 root mem    REG               0,41           3123176 /usr/lib/x86_64-linux-gnu/libssl.so.3 (path dev=0,68)
nginx     1 root mem    REG               0,41           3123161 /usr/lib/x86_64-linux-gnu/libpcre2-8.so.0.14.0 (path dev=0,68)
nginx     1 root mem    REG               0,41           3123120 /usr/lib/x86_64-linux-gnu/libcrypt.so.1.1.0 (path dev=0,68)
nginx     1 root DEL    REG                0,1              1025 /dev/zero
nginx     1 root mem    REG               0,41           3123093 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 (path dev=0,68)
nginx     1 root   0u   CHR                1,3      0t0        5 /dev/null
nginx     1 root   1w  FIFO               0,13      0t0 10873651 pipe
nginx     1 root   2w  FIFO               0,13      0t0 10873652 pipe
nginx     1 root   3u  unix 0x00000000a3184a13      0t0 10875931 type=STREAM (CONNECTED)
nginx     1 root   4w  FIFO               0,13      0t0 10873652 pipe
nginx     1 root   5w  FIFO               0,13      0t0 10873651 pipe
nginx     1 root   6u  IPv4           10875929      0t0      TCP *:80 (LISTEN)
nginx     1 root   7u  IPv6           10875930      0t0      TCP *:80 (LISTEN)
nginx     1 root   8u  unix 0x00000000dc7fdbea      0t0 10875932 type=STREAM (CONNECTED)
nginx     1 root   9u  unix 0x0000000036947168      0t0 10875933 type=STREAM (CONNECTED)
nginx     1 root  10u  unix 0x00000000d3bf8d5c      0t0 10875934 type=STREAM (CONNECTED)
nginx     1 root  11u  unix 0x0000000050db47c2      0t0 10875935 type=STREAM (CONNECTED)
nginx     1 root  12u  unix 0x000000008ed04f9a      0t0 10875936 type=STREAM (CONNECTED)
nginx     1 root  13u  unix 0x000000002c91e410      0t0 10875937 type=STREAM (CONNECTED)
nginx     1 root  14u  unix 0x00000000fc81b5b0      0t0 10875938 type=STREAM (CONNECTED)

kus

  • TODO

dockerhost peal

root@dh-post:~# lsof -n -P 2>&1 | grep 10873651
container 3235355                               root    3r     FIFO               0,13       0t0   10873651 pipe
container 3235355 3235356 container             root    3r     FIFO               0,13       0t0   10873651 pipe
container 3235355 3235357 container             root    3r     FIFO               0,13       0t0   10873651 pipe
container 3235355 3235358 container             root    3r     FIFO               0,13       0t0   10873651 pipe
container 3235355 3235359 container             root    3r     FIFO               0,13       0t0   10873651 pipe
container 3235355 3235360 container             root    3r     FIFO               0,13       0t0   10873651 pipe
container 3235355 3235361 container             root    3r     FIFO               0,13       0t0   10873651 pipe
container 3235355 3235362 container             root    3r     FIFO               0,13       0t0   10873651 pipe
container 3235355 3235363 container             root    3r     FIFO               0,13       0t0   10873651 pipe
container 3235355 3235364 container             root    3r     FIFO               0,13       0t0   10873651 pipe
container 3235355 3236396 container             root    3r     FIFO               0,13       0t0   10873651 pipe
nginx     3235379                               root    1w     FIFO               0,13       0t0   10873651 pipe
nginx     3235379                               root    5w     FIFO               0,13       0t0   10873651 pipe
nginx     3235458                    systemd-network    1w     FIFO               0,13       0t0   10873651 pipe
nginx     3235458                    systemd-network    5w     FIFO               0,13       0t0   10873651 pipe
nginx     3235459                    systemd-network    1w     FIFO               0,13       0t0   10873651 pipe
nginx     3235459                    systemd-network    5w     FIFO               0,13       0t0   10873651 pipe
nginx     3235460                    systemd-network    1w     FIFO               0,13       0t0   10873651 pipe
nginx     3235460                    systemd-network    5w     FIFO               0,13       0t0   10873651 pipe
nginx     3235461                    systemd-network    1w     FIFO               0,13       0t0   10873651 pipe
nginx     3235461                    systemd-network    5w     FIFO               0,13       0t0   10873651 pipe

root@dh-post:~# ps aux | grep -A 1 3235355
root     3235355  0.0  0.2 1235608 12780 ?       Sl   Jul05   0:03 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 5346ca828019f72091abce7126602450428a069de940c004500657906a8354b5 -address /run/containerd/containerd.sock
root     3235379  0.0  0.1  14884  7608 ?        Ss   Jul05   0:00 nginx: master process nginx -g daemon off;

kus

  • node '10873651' väärtus on globaalne, st konteineri ja dockerhost vaates jääb see samaks, see on seotud docker sees stdout peale logi kirjutava protsessi väljundis oleva pipe'iga

Kasulikud lisamaterjalid