8.26笔记

1. 环境的安装

 
  1. cat << EOF | tee /etc/modules-load.d/k8s.conf

  2. > overlay

  3. > br_netfilter

  4. > EOF

  5. overllay

  6. br_netfilter

  7. cat << EOF | tee /etc/sysctl.d/k8s.conf

  8. > net.bridge.bridge-nf-call-iptables = 1

  9. > net.bridge.bridge-nf-call-ip6tables = 1

  10. > net.ipv4.ip_forward = 1

  11. > EOF

  12. # yum 镜像

  13. # yum 服务器和客户端

2. 镜像案例

 
  1. # 启动服务

  2. systemctl start docker.service

  3. # 查看镜像

  4. docker images

  5. docker image ls

  6. # 删除镜像

  7. docker rmi centos:latest

  8. docker rmi 5axxxx(img id)

  9. # 在公共仓库查找镜像

  10. docker search centos

  11. # 拉取镜像

  12. docker pull centos

2. 管理容器 容器就是在镜像上添加了⼀个可写层

 
  1. # 创建容器

  2. docker run -it --name c0 centos:latest /bin/bash

  3. # 查看容器

  4. docker ps # 查看up的容器

  5. docker ps --all #查看所有的容器

  6. # 切回宿主 ctrl p q

  7. #启动容器

  8. docker start c0 c1

  9. #停⽤容器

  10. docker stop c0 c1

  11. #删除容器

  12. docker rm c0 c1

  13. # 如果容器正在运⾏,容器是删除的,如果容器没有删除,对应的镜

  14. 像也⽆法删除

镜像的迁移

 
  1. # save

  2. docker save -o centos.tar centos:latest

  3. # load

  4. docker save -i centos.tar

⽣成镜像

 
  1. # export 通过容器⽣成tar

  2. docker export centoshttpd.tar c0

  3. # import 通过tar引⼊镜像

  4. docker import -m "dafdsfa" centoshtpd centos:httpd

  5. docker images

获得镜像 ip 地址

 
  1. # 进⼊到镜像的bash

  2. yum install iprouter,net-tools

  3. ip a

  4. # 使⽤exec指令

  5. docker exec 容器名称或者id yum -y install iproute

  6. docker exec c0 ip a

  7. # 直接使⽤inspect命令

  8. dcoker inspoct c0

端⼝映射 -p

 
  1. docker run -it --name c0 -p80:80/tcp centos:latest

  2. /bin/bash

  3. docker run -it --name c1 -p80 centos:latest

  4. /bin/bash # 宿主会指定⼀个⼤于等于3278的端⼝给容器

  5. docker ps --all # 查看实际给予的端⼝

  6. docker run -it --name c2 -p10.1.1.51::80

  7. centos:latest /bin/bash

数据持久化

 
  1. docker run -it --name c4 -v /opt/:/var/www/html/

  2. centos:latest /bin/bash

线上考试系统的数据 虚拟化技术部署

1. 部署前段服务器

 
  1. # 1.将资源上传到服务器

  2. scp -r dist/ root@192.168.71.50:~

  3. # 2创建基础容器 在服务器上

  4. systemctl start docker.service

  5. docker pull centos

  6. docker run -it --name c0 centos:latest /bin/bash

  7. # 3 在容器中修改yum源

  8. curl -o /etc/yum.repos.d/CentOS-Base.repo

  9. https://mirrors.aliyun.com/repo/Centos-vault-

  10. 8.5.2111.repo

  11. yum clean all && yum makecache

  12. # 4.在容器中安装epel

  13. yum -y install epel-release

  14. # 5.在容器中安装nginx

  15. yum -y install nginx

  16. # 6.ctrl pq

  17. # 7.导出tar包

  18. docker export -o centos_nginx.tar

  19. # 8.引⼊tar包,称为镜像

  20. docker import -m "维护世界和平" centos_nginx.tar

  21. centos:nginx

  22. # 9.查看镜像

  23. docker image ls

  24. [root@localhost ~]# docker images

  25. REPOSITORY TAG IMAGE ID CREATED

  26. SIZE

  27. centos nginx 9afbddb29074 10 seconds

  28. ago 366MB

  29. mysql latest a82a8f162e18 4 weeks ago

  30. 586MB

  31. centos latest 5d0da3dc9764 2 years ago

  32. 231MB

  33. # 10.停⽤c0容器,删除c0容器

  34. # 11.创建新的centos nginx容器,在创建的同时指定端⼝,以及

  35. 挂载⽬录

  36. docker run -it --name c0 -p80:80/tcp -v

  37. /opt/:/usr/share/nginx/html centos:nginx /bin/bash

  38. # 12在容器内部启动nginx服务

  39. nginx

  40. #ctrl p q

  41. # 13 在宿主上把dist⽬录中的⽂件复制opt⽬录中

  42. cp -r dist/* /opt

1. 启动 docker 守护进程

[root@docker001 ~]# systemctl start docker.service

2. 搜索 mysql 镜像

 
  1. [root@docker001 ~]# docker search mysql

  2. NAME DESCRIPTION

  3. STARS OFFICIAL

  4. mysql MySQL is a widely used, opensource relation… 15322 [OK]

  5. bitnami/mysql Bitnami container image for

  6. MySQL 114

  7. google/mysql MySQL server for Google

  8. Compute Engine 25

  9. elestio/mysql Mysql, verified and packaged

  10. by Elestio 0

  11. rapidfort/mysql RapidFort optimized, hardened

  12. image for MySQL 25

  13. circleci/mysql MySQL is a widely used, opensource relation… 30

  14. ubuntu/mysql MySQL open source fast,

  15. stable, multi-thread… 64

  16. javanile/mysql MySQL for development

  17. 0

  18. eclipse/mysql Mysql 5.7, curl, rsync

  19. 1

  20. ilios/mysql Mysql configured for running

  21. Ilios 1

  22. cimg/mysql

  23. 3

  24. bitnamicharts/mysql

  25. 0

  26. mirantis/mysql

  27. 0

  28. docksal/mysql MySQL service images for

  29. Docksal - https://d… 0

  30. linuxserver/mysql A Mysql container, brought to

  31. you by LinuxSe… 41

  32. datajoint/mysql MySQL image pre-configured to

  33. work smoothly … 2

  34. ddev/mysql ARM64 base images for ddevdbserver-mysql-8.… 1

  35. phpmyadmin phpMyAdmin - A web interface

  36. for MySQL and M… 1017 [OK]

  37. vulhub/mysql

  38. 0

  39. drud/mysql

  40. 1

  41. nasqueron/mysql

  42. 1

  43. corpusops/mysql

  44. https://github.com/corpusops/docker-images/ 0

  45. jumpserver/mysql

  46. 1

  47. openeuler/mysql

  48. 0

  49. encoflife/mysql

  50. 0

3. 拉取 mysql 镜像

 
  1. [root@docker001 ~]# docker pull mysql

  2. Using default tag: latest

  3. latest: Pulling from library/mysql

  4. 6e839ac3722d: Pull complete

  5. ad912193ad5f: Pull complete

  6. 25d13d87fd8d: Pull complete

  7. 004d383c75ef: Pull complete

  8. 6d9bbc82a0b8: Pull complete

  9. 81fec07ea550: Pull complete

  10. 83357cb2d3a5: Pull complete

  11. 8ffe968b82c1: Pull complete

  12. 30dfd9a7ed57: Pull complete

  13. 35844ae33cbe: Pull complete

  14. Digest:

  15. sha256:86cdfe832c81e39a89cfb63c3fde1683c41cc00ef91e

  16. 67653c9c1df0ba80f454

  17. Status: Downloaded newer image for mysql:latest

  18. docker.io/library/mysql:latest

  19. [root@docker001 ~]# docker images

  20. REPOSITORY TAG IMAGE ID CREATED

  21. SIZE

  22. centos nginx 12fea1b890de 13 hours

  23. ago 366MB

  24. centos java17 b6bf774de7bb 14 hours

  25. ago 550MB

  26. centos_httpd v0 fffc96d791d5 39 hours

  27. ago 309MB

  28. centos_yum v0 191d9c84f461 39 hours

  29. ago 260MB

  30. mysql latest a82a8f162e18 4 weeks ago

  31. 586MB

  32. centos latest 5d0da3dc9764 2 years ago

  33. 231MB

4. 创建镜像容器

 
  1. [root@docker001 ~]# docker run -d --name my01 -e

  2. MYSQL_ROOT_PASSWORD=root -p 3306:3306 mysql:latest

  3. 9338d672d3d819e5eb35fcf9fb5cd8fe88daf5a84b00ab0a4b3

  4. 3fc9b9ba87d8a

  5. # -d 后台运⾏,并输出hashcode

  6. # -e MYSQL_ROOT_PASSWORD=root 设置mysql密码

  7. # -p 映射3306端⼝

5. 管理 mysql

 
  1. [root@docker001 ~]# docker exec -it my01 mysql -

  2. uroot -proot

  3. mysql: [Warning] Using a password on the command

  4. line interface can be insecure.

  5. Welcome to the MySQL monitor. Commands end with ;

  6. or \g.

  7. Your MySQL connection id is 9

  8. Server version: 9.0.1 MySQL Community Server - GPL

  9. Copyright (c) 2000, 2024, Oracle and/or its

  10. affiliates.

  11. Oracle is a registered trademark of Oracle

  12. Corporation and/or its

  13. affiliates. Other names may be trademarks of their

  14. respective

  15. owners.

  16. Type 'help;' or '\h' for help. Type '\c' to clear

  17. the current input statement.

  • 16
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值