Docker相關環境全套安裝文檔兼小技能

如下環境皆爲ubuntu16.04,主要安裝docker,docker-compose,docker倉庫等。python

Docker安裝

參考官方mysql

A: 有源安裝

sudo apt-get remove docker docker-engine docker.io
sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo apt-get update
apt-cache madison docker-ce
sudo apt-get install docker-ce=docker-ce=18.03.0~ce-0~ubuntu
sudo docker run hello-world

你也能夠使用這個腳本安裝:linux

sudo curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh -

B: 無源安裝

先下載已編譯包nginx

wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_18.06.1~ce~3-0~ubuntu_amd64.deb
sudo dpkg -i docker-ce_18.06.1~ce~3-0~ubuntu_amd64.deb
sudo docker run hello-world

在2017年的3月1號以後,Docker的版本命名開始發生變化,同時將CE版本和EE版本進行分開, 18.03表示18年3月發佈。git

離線安裝命名前docker(docker-engine depends on libltdl7 (>= 2.4.6);):github

wget https://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.1-0~xenial_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/main/libt/libtool/libltdl7_2.4.6-4_amd64.deb
dpkg -i *.deb

Docker-compose安裝

咱們能夠使用docker-compose來對多個容器進行管理。sql

離線安裝:docker

wget https://github.com/docker/compose/releases/download/1.8.1/docker-compose-`uname -s`-`uname -m`
 
mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

Docker Hub安裝

VMware公司開源的企業級的Docker Registry管理項目:harborjson

有了倉庫,咱們能夠直接push鏡像上去,而後從其餘地方拉,不用藉助U盤。ubuntu

安裝參考: 官方文章

環境依賴較新的docker1.10+docker-compose1.60+python2.7,咱們選擇離線安裝方式:

wget https://storage.googleapis.com/harbor-releases/release-1.6.0/harbor-offline-installer-v1.6.0-rc3.tgz
tar xvf harbor-offline-installer-v1.6.0-rc3.tgz
cd harbor

編輯docker-compose.yml

proxy:
    image: goharbor/nginx-photon:v1.6.0
    container_name: nginx
    restart: always
    volumes:
      - ./common/config/nginx:/etc/nginx:z
    networks:
      - harbor
    ports:
      - 8888:80
      - 1443:443
      - 4443:4443

修改common/templates/registry/config.yml文件加入8888端口:

vim common/templates/registry/config.yml

auth:
  token:
    issuer: harbor-token-issuer
    realm: $public_url:8888/service/token
    rootcertbundle: /etc/registry/root.crt
    service: harbor-registry

編輯harbor.cfg

hostname = 192.168.152.12
harbor_admin_password = admin

啓動並登錄:

sudo su
ufw allow 8888
./prepare
docker-compose up -d

打開:http://192.168.152.12:8888,帳號|密碼:admin

Docker配置

你能夠配置某些倉庫地址(第一個是阿里雲加速倉庫地址,第二個忽略https安全)

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://ztndgg1k.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.0.88:8888"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

而後登陸推送:

sudo docker login http://192.168.0.88:8888
sudo docker tag mysql:5.7 192.168.0.88:8888/public/mysql:5.7
docker push  192.168.0.88:8888/public/mysql:5.7

Docker特定場景使用

離線鏡像

若是不能訪問外網,那麼能夠用save和load來保存和加載鏡像

docker save xxx:1.0 > /root/api1.0.tar
docker  load < /root/api1.0.tar
docker images
相關文章
相關標籤/搜索