Docker configuration

Productivity Dec 01, 2019

Docs

docker 中文社区
docker build microservice
docker with spring-boot

Config Registry

https://xnfwm35f.mirror.aliyuncs.com
https://hdzyevnp.mirror.aliyuncs.com
https://zbhkub6p.mirror.aliyuncs.com
https://2h3po24q.mirror.aliyuncs.com

/etc/default/docker

DOCKER_OPTS="--registry-mirror=http://aad0405c.m.daocloud.io"

/etc/docker/daemon.json

{
  "debug" : true,
  "experimental" : true,
  "registry-mirrors" : [
    "https://hdzyevnp.mirror.aliyuncs.com"
  ]
}

Handle image

docker pull image_name:tag
docker images
docker save -o save_image_to_file.tar image_name
docker load -i saved_image_to_file.tar

docker export -o save_container_to_file.tar container_name
docker import  saved_container_to_file.tar

Compress image size : http://www.cnblogs.com/e2tox/p/4027756.html

Create private docker repository

docker run -d --hostname localhost --name registry-v2 -v $host_repos:/tmp/registry-dev/docker/registry/v2 -p 5000:5000 registry:2.0

Backup data from container

  1. docker run -dit  -v /data:/data  --name node image_name
  2. docker run -it --rm --volumes-from node  -v local_path:/dest_path  image_name   cp -rf /data  /dest_path
  3. target data will be copied to local_path

Expose port

docker -p local_port:container_port/[tcp|udp]

Share volumes

docker -v local_path:container_path

容器管理工具

Rancher,  CoreOS

https://portainer.io

Ubuntu & Debian

Debian with docker

apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
apt update
apt-cache policy docker-ce
apt install -y docker-ce docker-ce-cli containerd.io
bash

CentOS

CentOS with docker

Enable centos-extras mirror

# Remove previous docker

yum remove docker \
  docker-client \
  docker-client-latest \
  docker-common \
  docker-latest \
  docker-latest-logrotate \
  docker-logrotate \
  docker-engine
yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io
systemctl enable docker.service
systemctl start docker.service

Install

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
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker

Nightly

sudo yum-config-manager --enable docker-ce-nightly
# or 
# sudo yum-config-manager --disable docker-ce-nightly

Test

sudo yum-config-manager --enable docker-ce-test

Fedora

Fedora with docker

sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
# Enable nightly channel
sudo dnf config-manager --set-enabled docker-ce-nightly
# Enable test channel
sudo dnf config-manager --set-enabled docker-ce-test
# Disable test channel
sudo dnf config-manager --set-disabled docker-ce-test
sudo dnf install docker-ce docker-ce-cli containerd.io

Nicholas X.

山穷水复疑无路,柳暗花明又一村