linux下docker环境及docker-compose环境安装

Table of Contents

一、docker环境搭建

官网安装地址

  1. 卸载旧版本

    较旧的Docker版本称为dockerdocker-engine。如果已安装这些程序,请卸载它们以及相关的依赖项。

    1
    2
    3
    4
    5
    6
    7
    8
    sudo yum remove docker \
    docker-client \
    docker-client-latest \
    docker-common \
    docker-latest \
    docker-latest-logrotate \
    docker-logrotate \
    docker-engine
  2. 安装依赖

    1
    2
    3
    4
    5
    sudo yum install -y yum-utils

    sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
  3. 安装docker

    1
    sudo yum install docker-ce docker-ce-cli containerd.io
  4. 查看docker版本

    1
    docker -v

二、docker-compose环境搭建

官网安装地址

  1. 运行以下命令以下载Docker Compose的当前稳定版本

    1
    sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. 将可执行权限应用于二进制文件

    1
    sudo chmod +x /usr/local/bin/docker-compose
  3. 查看docker-compose版本

    1
    docker-compose -v

三、docker配置文件修改

  1. 修改配置文件(如果文件不存在,创建一个)

    vim /etc/docker/daemon.json

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    {
    "debug": true,
    "registry-mirrors": [
    "http://hub-mirror.c.163.com",
    "https://registry.aliyuncs.com",
    "https://registry.docker-cn.com",
    "https://docker.mirrors.ustc.edu.cn"
    ],
    "insecure-registries": [
    "ip:host"
    ],
    "experimental": true
    }
  2. 重启docker
    systemctl start docker.service
    systemctl status docker.service

四、docker常用命令

  1. 容器命令

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    docker ps	# 查看正在运行容器
    docker ps -a # 查看所有容器
    docker run -dit --name=crawld -p 30030:10002 deb7db7d4b75 # 启动容器。对外端口:容器端口
    docker logs --details 82d68c1534c6 # 查看日志
    docker logs -f -t --since="2020-05-29" --tail=10 b18698736657 # 查看指定日期之后的日志
    docker stop 82d68c1534c6 # 停止容器
    docker rmf deb7db7d4b75 # 删除容器
    docker exec -it 97191593e2b2 /bin/bash # 进入容器
    docker tag skywalking/ui:8.0.1 ip:port/basic-servers/skywalking-ui:8.0.1 # Tag标记本地镜像
    docker push ip:port/basic-servers/skywalking-ui:8.0.1 # 镜像上传
  2. 镜像命令

    1
    2
    3
    docker pull docker.io/airdock/oracle-jdk	# 拉取镜像(jdk为例)
    docker build -t api-gateway:v1 . # 生成镜像。将当前目录打包并生成名字叫api-gateway的镜像
    docker rmi api-gateway:v1 # 删除镜像

五、docker-compose

  1. docker-compose命令

    1
    2
    3
    4
    docker-compose up -d	# 启动容器
    docker-compose stop # 停止容器
    docker-compose rm # 删除容器
    docker-compose restart # 重启容器
  2. docker-compose.yml示例

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    version: '3.3'
    services:
    elasticsearch:
    image: elasticsearch:7.1.1
    container_name: elasticsearch
    restart: always
    privileged: true
    user: root
    ports:
    - 9200:9200
    environment:
    discovery.type: single-node
    TZ: Asia/Shanghai
    volumes:
    - ./elasticsearch/logs:/usr/share/elasticsearch/logs
    - ./elasticsearch/data:/usr/share/elasticsearch/data
    - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    #- /etc/localtime:/etc/localtime
    ulimits:
    memlock:
    soft: -1
    hard: -1
    oap:
    image: skywalking-oap:8.0.1
    container_name: oap
    depends_on:
    - elasticsearch
    links:
    - elasticsearch
    restart: always
    ports:
    - 11800:11800
    - 12800:12800
    environment:
    SW_STORAGE: elasticsearch7
    SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
    TZ: Asia/Shanghai
    volumes:
    - ./config/alarm-settings.yml:/skywalking/config/alarm-settings.yml
    #- /etc/localtime:/etc/localtime
    # - ./config/server-core-6.6.0.jar:/skywalking/oap-libs/server-core-6.6.0.jar
    # - ./config/storage-elasticsearch-plugin-6.6.0.jar:/skywalking/oap-libs/storage-elasticsearch-plugin-6.6.0.jar
    ui:
    image: skywalking-ui:8.0.1
    container_name: ui
    depends_on:
    - oap
    links:
    - oap
    restart: always
    ports:
    - 8080:8080
    environment:
    SW_OAP_ADDRESS: oap:12800
    TZ: Asia/Shanghai
    #volumes:
    # - /etc/localtime:/etc/localtime

评论系统未开启,无法评论!