FAQ - 常見問題

    cron job 無法執行 docker-compose

    Error:the input device is not a TTY

    解決:加上 -T

    docker-compose exec -T .....
    

    Docker Container 自動啟動

    將 container 以 systemd 設定自動啟動

    /etc/systemd/system/ddns-server-ct.service

    [Unit]
    Description=DDNS Server Docker Container
    After=docker.service
    Requires=docker.service
    Requires=network.target
    [Service]
    Type=oneshot
    TimeoutStartSec=240
    Restart=no
    RemainAfterExit=yes
    ExecStart=/usr/bin/docker start ddns-server
    ExecStop=/usr/bin/docker stop ddns-server
    [Install]
    WantedBy=multi-user.target
    chmod 664 /etc/systemd/system/ddns-server-ct.service
    systemctl daemon-reload
    systemctl enable ddns-server-ct.service

    時區設定與 Host 保持一致

    Host 與 Container 都是 CentOS

    啟動 container 加上

    -v /etc/localtime:/etc/localtime:ro
    
    Host 與 Container 都是 Debian 為例

    1. 在 container 的啟動檔裡加上這些內容

    function setTimeZone {
        if [ -f "/etc/timezone.host" ]; then
            CLIENT_TIMEZONE=$(cat /etc/timezone)
            HOST_TIMEZONE=$(cat /etc/timezone.host)
    
            if [ "${CLIENT_TIMEZONE}" != "${HOST_TIMEZONE}" ]; then
                echo "Reconfigure timezone to "${HOST_TIMEZONE}
                echo ${HOST_TIMEZONE} > /etc/timezone
                dpkg-reconfigure -f noninteractive tzdata
            fi
        fi
    }
    
    setTimeZone

    2. 啟動 container 時,加上 --net host

    $ docker run -d -it \
    -v /var/log:/var/log \
    --name fail2ban \
    --net host \
    --privileged \
    superitman/fail2ban:latest
    

    Container 缺少的常用套件安裝

    CentOS 5.x)

    crond, crontab

    yum install vixie-cron
    service crond start 
    

    bzip2
    NOTE: 缺少這個,無法解壓 xxx.tar.bz2

    yum install bzip2
    

    無法刪除 image ?

    刪除 image 出現錯誤

    Error response from daemon: No such id: 3076561ea5b708c9f...

    Ans:

    1. 先找出這個 image 的 container-id

    # docker ps -a
    
    CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                         PORTS               NAMES
    16c3e588af5c        3076561ea5b7        "/bin/bash"            21 minutes ago      Exited (0) 13 minutes ago                          grave_leakey
    c03d604fab30        centos:centos5      "/bin/bash"            51 minutes ago      Exited (0) 51 minutes ago    
    

    2. 刪除 container

    # docker rm 16c3e588af5c
    

    3. 再一次刪除 image

    # docker rmi 3076561ea5b7
    
    標籤 (Edit tags)
    • No tags
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core