Docker

作者: 古飞_数据 | 来源:发表于2021-08-21 07:04 被阅读0次

4C/8G-Cenos7.9

安装docker和docker-compose

#删除系统自带的Docker
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
#安装官方的docker repo
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#安装docker
yum install -y docker-ce docker-ce-cli containerd.io

#配置docker镜像源和数据目录
#自动创建目录/data/docker
mkdir /etc/docker
cat >/etc/docker/daemon.json <<EOF
{
  "registry-mirrors": ["https://mirror.ccs.tencentyun.com"],
  "data-root": "/data/docker" 
}
EOF

#安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

docker管理

#启动docker
systemctl start docker
#关闭docker
systemctl stop docker
#查看镜像
docker images
#查看运行中的容器
docker ps
#查看所有的容器,包括运行和停止的
docker ps -a
#拉取最新的镜像
docker pull mysql/mysql-server:latest
#查看images的信息
docker inspect mysql/mysql-server:latest
docker run --name=mysql3306 -d mysql/mysql-server:latest
docker ps
docker volume ls

docker logs mysql3306
docker exec -it mysql3306 /bin/bash

docker stop mysql3306
docker rm mysql3306
1.停用全部运行中的容器:
docker stop $(docker ps -q)

2.删除全部容器:
docker rm $(docker ps -aq)

3.删除所有镜像
docker rmi $(docker images -qa)

docker stop $(docker ps -qa)
docker rm $(docker ps -qa)
docker rmi $(docker images -qa)

docker+Redis搭建

cd /data/docker
mkdir redis
cd redis/

[root@VM-0-32-centos redis]# tree ../redis/
../redis/
|-- build
|   `-- Dockerfile
|-- data
|-- docker-compose.yml
`-- redis.conf


vi build/Dockerfile
From redis
CMD ["redis-server","/etc/redis/redis.conf"]


vi docker-compose.yml
version: '3.1'
services:
  redis:
    build: build
    container_name: redis
    restart: always
    ports:
      - 6379:6379
    volumes:
      - ./data:/data
      - ./redis.conf:/etc/redis/redis.conf
    

docker-compose up -d
docker ps

docker exec -it redis /bin/bash

=========================================================

docker+nginx搭建

[root@VM-0-32-centos nginx]# tree ../nginx/
../nginx/
|-- build
|   |-- Dockerfile
|   `-- nginx-1.17.7.tar.gz
|-- docker-compose.yml
|-- log
|-- nginx.conf
`-- wwwroot

vi build/Dockerfile
-------------
FROM centos:7
RUN yum install unzip make gcc gcc-c++ automake autoconf pcre pcre-devel zlip zlib-devel -y
ADD nginx-1.17.7.tar.gz /usr/local/src
WORKDIR /usr/local/src/nginx-1.17.7
RUN ./configure
RUN make && make install
WORKDIR /
CMD ["/usr/local/nginx/sbin/nginx","-c","/usr/local/nginx/conf/nginx.conf","-g","daemon off;"]

nginx.conf
version: '3.1'
services:
  nginx:    
    build: build
    container_name: nginx
    restart: always
    ports:
      - 80:80
    volumes:
      - ./nginx.conf:/usr/local/nginx/conf/nginx.conf
      - ./log:/var/log/nginx
      - ./wwwroot:/usr/local/nginx/html 

      
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}


curl 127.0.0.1

================================

docker+mysql8

[root@VM-0-32-centos mysql8]# tree ../mysql8/
../mysql8/
|-- data
|-- docker-compose.yml
`-- my.cnf

#docker-compose.yml
version: '3.1'
services:
  mysql:
    image: mysql:8.0.18
    restart: always
    ports:
      - 3306:3306
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
    environment:
      MYSQL_ROOT_PASSWORD: 123
    volumes:
      - ./data:/var/lib/mysql
      - ./my.cnf:/etc/my.cnf
# 监控    
#  mysqld_exporter:
#    image: prom/mysqld_exporter
#   restart: always
#   network_mode: host
#   environment:
#     - DATA_SOURCE_NAME=root:123@(127.0.0.1:3306)/

#my.cnf   
[mysqld]
datadir = /var/lib/mysql
port = 3306
socket = /var/run/mysqld/mysqld.sock
pid-file = /var/run/mysqld/mysqld.pid
symbolic-links=0
#timeout
interactive_timeout = 300
wait_timeout = 300

#character set
character-set-server = utf8mb4

open_files_limit = 65535
max_connections = 100

解决cpu 100%问题

解决agetty进程cpu占用率100%,宿主机和容器需要执行

systemctl stop getty@tty1.service
systemctl mask getty@tty1.service

相关文章

  • docker学习

    docker镜像 docker容器 docker仓库 安装docker docker版本 docker分为社区版和...

  • Docker安装和运行

    获取Docker 安装Docker 验证安装 1、获取Docker Docker for Mac Docker f...

  • Docker知识手册

    Docker 容器 启动docker:docker start 查看docker运行状态:docker stats...

  • Docker简介

    章节介绍 # Docker是什么# Docker包括什么# Docker镜像# Docker编配# Docker还...

  • Docker 常用操作

    Docker docker: 18.09.4、nvidia-docker: 2.0.3 docker 19.03 ...

  • rancher+harbor离线安装

    安装docker,此docker为社区版docker。docker官方文档:https://docs.docker...

  • Linux之Docker

    Linux之Docker 目录 Docker简单介绍 在线Docker安装 离线Docker安装 Docker简单...

  • Docker常用命令

    Docker常用命令 Docker帮助命令 docker version:查看docker版本 docker in...

  • Docker基础操作

    Docker部署 Docker安装 镜像加速 Docker 基础命令 Docker镜像管理 搜索镜像docker ...

  • docker容器状态查看命令集

    docker inspect 用法 : docker inspect [docker名称/docker short...

网友评论

    本文标题:Docker

    本文链接:https://www.haomeiwen.com/subject/sugtiltx.html