Tag: docker

  • docker server gave HTTP response to HTTPS client

    Add /etc/docker/daemon.json with this 192.168.1.1:5000 (registry IP and port), and restart docker

    {
    “insecure-registries”: [“192.168.1.1:5000”]
    }

  • Docker pull error: Invalid registry endpoint https on Centos 7.1

    Error: docker pull does not work on insecure connection by default

    Solution for Centos 7: Add –insecure-registry option

    1. Edit /lib/systemd/system/docker.service:

    [Unit]
    Description=Docker Application Container Engine
    Documentation=https://docs.docker.com
    After=network.target docker.socket
    Requires=docker.socket

    [Service]
    EnvironmentFile=-/etc/sysconfig/docker
    Type=notify
    ExecStart=/usr/bin/docker daemon $other_args -H fd://
    MountFlags=slave
    LimitNOFILE=1048576
    LimitNPROC=1048576
    LimitCORE=infinity

    [Install]
    WantedBy=multi-user.target

    2. Edit /etc/sysconfig/docker

    other_args=”–insecure-registry registry_ip:port

    3. Restart docker daemon:

    sudo systemctl daemon-reload
    sudo service docker restart

  • Copy and Import Docker Images using docker save and docker load command

    1. Save docker image as a tar file:

    docker save -o tar_filename image_name

    2. Copy the tar file to new host and import the image from tar file:

    docker load -i tar_filename

  • Run multiple command in docker

    To run multiple commands in docker, use /bin/bash -c and semicolon ; to separate the commands. For example: change directory and run a python script:
    docker run image /bin/bash -c “cd /path/to/somewhere; python a.py”
  • Pull centos docker image

    To pull centos as a base image to build other docker images:

     docker pull centos:centosX

    Where X can be 5, 6 or 7

  • Run docker registry on port 5000

    Command: docker run -p 5000:5000 registry

  • Unclean shutdown detected when using mongodb docker

    When stopping a docker with mongod daemon running using command:

    docker stop <container_id>

    the next time you start the mongod docker, it will complain about unclean shutdown detected:

    “Unclean shutdown detected.
    Please visit http://dochub.mongodb.org/core/repair for recovery
    instructions.”

    Cause: “docker stop” use SIGTERM to kill mongod daemon, while it is recommended to use SIGINT

    Solution:

    docker kill -s INT <container_id>

  • Docker exited with code 1

    Error: docker run with  Exited (1)

    Cause: the CMD you run inside the docker exits with error

    Solution: Check the error in docker log by these steps:

    1. sudo docker ps -a

    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    f4c94eb133b4 dockername:latest “httpd”  55 seconds ago  Exited (1) 54 seconds ago0.0.0.0:80->80/tcp webserver

    2. sudo docker logs CONTAINER_ID

  • Docker clean up defunct/untagged images using rm and rmi

    The following 2 commands will do the job:

    sudo docker ps -a | grep ‘Exited’ | awk ‘{print $1}’ | xargs –no-run-if-empty sudo docker rm
    sudo docker images | grep ‘none’ | awk ‘{print $3}’ | xargs –no-run-if-empty sudo docker rmi