The latest docker installation tutorial

Install docker tutorial

Reference website: https://developer.aliyun.com/article/110806

Official documentation: https://docs.docker.com/engine/install/centos/

Official website: https://docs.docker.com/

Docker CE mirror source site

Automatic installation using the official installation script

(Only applicable to public network environment)

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

Manual installation help

(Alibaba Cloud ECS can be installed through the intranet, see the comments section)

Ubuntu 14.04 16.04

(Use apt-get to install)

# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书e
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装 Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce

注意:其他注意事项在下面的注释中
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# apt-cache madison docker-ce
#   docker-ce | 17.03.1~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages
#   docker-ce | 17.03.0~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages
# Step 2: 安装指定版本的Docker-CE: (VERSION 例如上面的 17.03.1~ce-0~ubuntu-xenial)
# sudo apt-get -y install docker-ce=[VERSION]

# 通过经典网络、VPC网络内网安装时,用以下命令替换Step 2、Step 3中的命令
# 经典网络:
# curl -fsSL http://mirrors.aliyuncs.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyuncs.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# VPC网络:
# curl -fsSL http://mirrors.cloud.aliyuncs.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# sudo add-apt-repository "deb [arch=amd64] http://mirrors.cloud.aliyuncs.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

CentOS 7

(Use yum to install)

# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装 Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start

注意:其他注意事项在下面的注释中
# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,你可以通过以下方式开启。同理可以开启各种测试版本等。
# vim /etc/yum.repos.d/docker-ce.repo
#   将 [docker-ce-test] 下方的 enabled=0 修改为 enabled=1
#
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
#   Loading mirror speeds from cached hostfile
#   Loaded plugins: branch, fastestmirror, langpacks
#   docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable
#   docker-ce.x86_64            17.03.1.ce-1.el7.centos            @docker-ce-stable
#   docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable
#   Available Packages
# Step2 : 安装指定版本的Docker-CE: (VERSION 例如上面的 17.03.0.ce.1-1.el7.centos)
# sudo yum -y install docker-ce-[VERSION]
# 注意:在某些版本之后,docker-ce安装出现了其他依赖包,如果安装失败的话请关注错误信息。例如 docker-ce 17.03 之后,需要先安装 docker-ce-selinux。
# yum list docker-ce-selinux- --showduplicates | sort -r
# sudo yum -y install docker-ce-selinux-[VERSION]

# 通过经典网络、VPC网络内网安装时,用以下命令替换Step 2中的命令
# 经典网络:
# sudo yum-config-manager --add-repo http://mirrors.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
# VPC网络:
# sudo yum-config-manager --add-repo http://mirrors.could.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo

Installation verification

root@iZbp12adskpuoxodbkqzjfZ:$ docker version
Client:
 Version:      17.03.0-ce
 API version:  1.26
 Go version:   go1.7.5
 Git commit:   3a232c8
 Built:        Tue Feb 28 07:52:04 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.03.0-ce
 API version:  1.26 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   3a232c8
 Built:        Tue Feb 28 07:52:04 2017
 OS/Arch:      linux/amd64
 Experimental: false

Mirror accelerator

Reference URL: https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

Other accelerators: https://www.daocloud.io/mirror

Using accelerators can increase the speed of obtaining official Docker images

Insert picture description here

Acceleration address: https://1sbmxpab.mirror.aliyuncs.com

Operation document

  • Ubuntu

For users whose Docker client version is greater than 1.10.0

You can use the accelerator by modifying the daemon configuration file /etc/docker/daemon.json

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    
    
  "registry-mirrors": ["https://1sbmxpab.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
  • CentOS

For users whose Docker client version is greater than 1.10.0

You can use the accelerator by modifying the daemon configuration file /etc/docker/daemon.json

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    
    
  "registry-mirrors": ["https://1sbmxpab.mirror.aliyuncs.com"]
}
EOF
#配置完之后记得重启服务
sudo systemctl daemon-reload
sudo systemctl restart docker
  • Mac

1. Install/upgrade Docker client

It is recommended to use Docker Toolbox for users below 10.10.3

Mac installation file: http://mirrors.aliyun.com/docker-toolbox/mac/docker-toolbox/

For users above 10.10.3, Docker for Mac is recommended

Mac installation file: http://mirrors.aliyun.com/docker-toolbox/mac/docker-for-mac/

2. Configure Mirror Accelerator

For users who have installed Docker Toolbox, you can refer to the following configuration steps:

Create a Linux virtual machine with Docker environment installed, specify the machine name as default, and configure the Docker accelerator address.

docker-machine create --engine-registry-mirror=https://1sbmxpab.mirror.aliyuncs.com -d virtualbox default

Check the environment configuration of the machine and configure it locally, and access the Docker service through the Docker client.

docker-machine env defaulteval "$(docker-machine env default)"docker info

For users who have installed Docker for Mac, you can refer to the following configuration steps:

Click the Docker Desktop application icon -> Perferences in the task bar, select Docker Engine in the left navigation menu, and edit the json file in the right input field. will

https://1sbmxpab.mirror.aliyuncs.com is added to the "registry-mirrors" array, click the Apply & Restart button, wait for Docker to restart and apply the configured mirror accelerator.

3. Whether the test is successful

docker info

Insert picture description here

Docker create container

Reference website: https://hub.docker.com/

Common commands

Find the mirror

docker search image
docker search tomcat

Pull mirror

docker pull image(镜像名称):tags
docker pull tomcat:jdk15-openjdk-oracle

View mirror

docker image ls
docker images

Delete mirror

docker rmi 镜像ID
docker rmi 040bdb29ab37

Make a container by mirroring

docker run --name 容器名称 -p 宿主机端口:容器端口 -d 镜像名称
docker run --name mytomcat -p 8080:8080 -d tomcat

View the made container

#查看运行中的容器
docker ps
#查看所有容器
docker ps -a

#进入容器内部
docker exec -it 容器ID /bin/bash
docker exec -it f3ff9c0a6ad5 /bin/bash
#进入容器之后就可以操作里面的文件夹和文件了
#进入容器命令
docker exec -it 9fbe362214a6(容器Id)  /bin/bash   
#通过这两个命令可以安装vim命令
apt-get update
apt-get install vim

#使用docker安装mysql
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql

Docker Compose

installation

Reference address: https://docs.docker.com/compose/install/

#1.Run this command to download the current stable release of Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#2.Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
#3.Test the installation.
$ docker-compose --version
docker-compose version 1.27.4, build 1110ad01

mysql

version: '3.1'
services:
  db:
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 123456
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
    ports:
      - 3306:3306
    volumes:
      - ./data:/var/lib/mysql

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

Start mysql

docker-compose up -d

stop

docker-compose down

Guess you like

Origin blog.csdn.net/weixin_55580097/article/details/114114164