Categories

Install Docker on a Mac

Download Docker.dmg from this link, then install it. Or, you can also use brew to install.

brew cask install docker

Install Docker on CentOS

# https://docs.docker.com/install/linux/docker-ce/centos/
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
# If you want to install a specific version:
# Show the available versions
# yum list docker-ce --showduplicates | sort -r
# yum install -y docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
sudo systemctl start docker

Docker Registry in China

Update registry-mirrors

Update in /etc/docker/daemon.json

{
  "registry-mirrors": [
    "https://registry.docker-cn.com"
  ]
}

Setup and Deploy Docker Registry Server

docker run \
  --name registry \
  --restart always \
  -p 5000:5000 \
  -e REGISTRY_PROXY_REMOTEURL=https://registry.docker-cn.com \
  -e REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry \
  -e REGISTRY_STORAGE_DELETE_ENABLED: "true" \
  -v $(pwd)/data:/var/lib/registry -d registry:2

Tool: Harbor

Installation

Remove Images from Docker Regsitry

# https://github.com/andrey-pohilko/registry-cli
docker run --rm anoxis/registry-cli -r https://172.17.0.1:5000 --delete-all --no-validate-ssl
docker exec registry bin/registry garbage-collect /etc/docker/registry/config.yml

Tools: Dive

Dive: A tool for exploring each layer in a docker image

Trick using Docker

  • Get Env

    docker exec container bash -c 'echo "$ENV_VAR"'
    

    https://stackoverflow.com/questions/34051747/get-environment-variable-from-docker-container/34052766

  • Get Container IP Address

    docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_name_or_id
    docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
    

    https://stackoverflow.com/questions/17157721/how-to-get-a-docker-containers-ip-address-from-the-host

Docker Images

Reference