最全【Docker】docker日常工作总结(涉及基础命令、基础名词概念,2024年最新这些大数据开发高级必会知识点你能答出来几个

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker image rm -f nginx:alpine

🌙3、查看镜像的历史记录

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker history nginx

🌙4、下载镜像

1、sudo docker search redis:查看镜像相关的安装包(例如查看redis相关的安装包,建议使用官方的安装包)
2、也可以百度docker hub去获取相关的安装包https://registry.hub.docker.com/

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker search redis
NAME                                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
redis                                              Redis is an open source key-value store that…   10992     [OK]       
bitnami/redis                                      Bitnami Redis Docker Image                      220                  [OK]
bitnami/redis-sentinel                             Bitnami Docker Image for Redis Sentinel         37                   [OK]
bitnami/redis-cluster                                                                              32                   
rapidfort/redis                                    RapidFort optimized, hardened image for Redi…   14                   
rapidfort/redis-cluster                            RapidFort optimized, hardened image for Redi…   14                   
circleci/redis                                     CircleCI images for Redis                       13                   [OK]
ubuntu/redis                                       Redis, an open source key-value store. Long-…   10                   
bitnami/redis-exporter                                                                             7                    
clearlinux/redis                                   Redis key-value data structure server with t…   4                    
google/guestbook-python-redis                      A simple guestbook example written in Python…   4                    
ibmcom/redis-ha                                                                                    1                    
bitnami/redis-sentinel-exporter                                                                    1                    
ibmcom/ibm-cloud-databases-redis-operator          Container image for the IBM Operator for Red…   1                    
ibmcom/ibm-cloud-databases-redis-operator-bundle   Bundle image for the IBM Operator for Redis     1                    
ibmcom/ibm-cloud-databases-redis-catalog           Catalog image for the IBM Operator for Redis    1                    
ibmcom/redis-ppc64le                                                                               0                    
blackflysolutions/redis                            Redis container for Drupal and CiviCRM          0                    
ibmcom/redisearch-ppc64le                                                                          0                    
drud/redis                                         redis                                           0                    [OK]
rancher/redislabs-ssl                                                                              0                    
vmware/redis-photon                                                                                0                    
cimg/redis                                                                                         0                    
newrelic/k8s-nri-redis                             New Relic Infrastructure Redis Integration (…   0                    
astronomerinc/ap-redis                             Redis service for Airflow's celery executor …   0    

🌙5、拉取镜像

如果在拉取镜像时没有指定版本号,默认拉取的是最新的,例如sudo docker pull python
例如:拉取指定的版本:sudo docker pull mysql:5.7

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker pull python
Using default tag: latest
latest: Pulling from library/python
e756f3fdd6a3: Pull complete 
bf168a674899: Pull complete 
e604223835cc: Pull complete 
6d5c91c4cd86: Pull complete 
2cc8d8854262: Pull complete 
2767dbfeeb87: Pull complete 
e5f27d860d89: Pull complete 
98a3e4f5f5ed: Pull complete 
af265a3ad3e0: Pull complete 
Digest: sha256:bef6fd726fb8825d5cf26933d8477505b14505be1a98394405c8840c1c266bdd
Status: Downloaded newer image for python:latest
docker.io/library/python:latest

🌙6、查看镜像的详细信息

sudo docker inspect python:latest(镜像名:tag)

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker inspect python:latest

🌙7、查看容器:

sudo docker ps:查看正在运行的容器
sudo docker ps -a:查看所有的容器
sudo docker container ls:查看正在运行的容器
sudo docker container ls --all :查看所有的容器

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker container ls
CONTAINER ID   IMAGE                 COMMAND                  CREATED        STATUS        PORTS                                                                                        NAMES
bca70facba90   nginx:alpine          "/docker-entrypoint.…"   3 hours ago    Up 3 hours    0.0.0.0:49160->80/tcp, :::49160->80/tcp                                                      web4
ff2d3c951eed   nginx:alpine          "/docker-entrypoint.…"   3 hours ago    Up 3 hours    0.0.0.0:49159->80/tcp, :::49159->80/tcp                                                      web3
4011f219f403   nginx:alpine          "/docker-entrypoint.…"   3 hours ago    Up 3 hours    0.0.0.0:49158->80/tcp, :::49158->80/tcp                                                      web2
d992bc0fa330   nginx                 "/docker-entrypoint.…"   3 hours ago    Up 3 hours    80/tcp                                                                                       nginx_test
2c4108268aa9   jenkins/jenkins:lts   "/sbin/tini -- /usr/…"   25 hours ago   Up 25 hours   0.0.0.0:49154->8080/tcp, :::49154->8080/tcp, 0.0.0.0:49153->50000/tcp, :::49153->50000/tcp   jenkins
ae1fd6dd1b00   mysql                 "docker-entrypoint.s…"   3 weeks ago    Up 3 days     0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                                         mysql

🌙8、运行容器

1、sudo docker run redis:redis是一个镜像,首先去本地查看有没有redis的镜像,如果有直接去运行,如果没有,默认去docker hub官方镜像中拉取到本地
2、如果后面没有指名版本号,等价于sudo docker run redis:latest(最新的)

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker run redis
Unable to find image 'redis:latest' locally
latest: Pulling from library/redis
42c077c10790: Already exists 
a300d83d65f9: Pull complete 
ebdc3afaab5c: Pull complete 
31eec7f8651c: Pull complete 
9c6a6b89d274: Pull complete 
5c8099a4b45c: Pull complete 
Digest: sha256:1b90dbfe6943c72a7469c134cad3f02eb810f016049a0e19ad78be07040cdb0c
Status: Downloaded newer image for redis:latest
1:C 02 Jun 2022 05:36:13.616 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 02 Jun 2022 05:36:13.616 # Redis version=7.0.0, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 02 Jun 2022 05:36:13.616 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 02 Jun 2022 05:36:13.616 \* monotonic clock: POSIX clock_gettime
1:M 02 Jun 2022 05:36:13.617 \* Running mode=standalone, port=6379.
1:M 02 Jun 2022 05:36:13.617 # Server initialized
1:M 02 Jun 2022 05:36:13.617 # WARNING overcommit\_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit\_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit\_memory=1' for this to take effect.
1:M 02 Jun 2022 05:36:13.618 \* The AOF directory appendonlydir doesn't exist
1:M 02 Jun 2022 05:36:13.618 \* Ready to accept connections

^C1:signal-handler (1654148179) Received SIGINT scheduling shutdown...
1:M 02 Jun 2022 05:36:19.649 # User requested shutdown...
1:M 02 Jun 2022 05:36:19.649 \* Saving the final RDB snapshot before exiting.
1:M 02 Jun 2022 05:36:19.649 \* DB saved on disk
1:M 02 Jun 2022 05:36:19.649 # Redis is now ready to exit, bye bye...

默认运行一个容器时容器名称是随机生成的

在这里插入图片描述

运行的时候指定容器名称,容器名称必须唯一
- -name :给容器指定名称
- -name与容器名称在一块,不能分开

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker run --name centos_t1 centos 

-it:运行容器,并且进入容器中
退出容器:exit

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker run -it --name centos_t2 centos
[root@90f0e8d75990 /]# 

✨例如:进入到centos容器中了

在这里插入图片描述

选择tag,建议使用alpine:非常小

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker run --name nginx_1 nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/06/02 05:58:04 [notice] 1#1: using the "epoll" event method
2022/06/02 05:58:04 [notice] 1#1: nginx/1.21.6
2022/06/02 05:58:04 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
2022/06/02 05:58:04 [notice] 1#1: OS: Linux 5.13.0-40-generic
2022/06/02 05:58:04 [notice] 1#1: getrlimit(RLIMIT\_NOFILE): 1048576:1048576
2022/06/02 05:58:04 [notice] 1#1: start worker processes
2022/06/02 05:58:04 [notice] 1#1: start worker process 31
2022/06/02 05:58:04 [notice] 1#1: start worker process 32
2022/06/02 05:58:04 [notice] 1#1: start worker process 33
2022/06/02 05:58:04 [notice] 1#1: start worker process 34
2022/06/02 05:58:06 [notice] 1#1: signal 28 (SIGWINCH) received

宿主机(ubuntu)的端口映射容器端口(访问宿主机中的1111端口相当于访问容器中的80端口)
-p:手动指定端口
-P:不需要手动指定端口,会随机的指定端口

✨例如启动nginx手动指定端口

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker run --name nginx_2 -p 1111:80 nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/06/02 06:06:19 [notice] 1#1: using the "epoll" event method
2022/06/02 06:06:19 [notice] 1#1: nginx/1.21.6
2022/06/02 06:06:19 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
2022/06/02 06:06:19 [notice] 1#1: OS: Linux 5.13.0-40-generic
2022/06/02 06:06:19 [notice] 1#1: getrlimit(RLIMIT\_NOFILE): 1048576:1048576
2022/06/02 06:06:19 [notice] 1#1: start worker processes
2022/06/02 06:06:19 [notice] 1#1: start worker process 32
2022/06/02 06:06:19 [notice] 1#1: start worker process 33
2022/06/02 06:06:19 [notice] 1#1: start worker process 34
2022/06/02 06:06:19 [notice] 1#1: start worker process 35
^C2022/06/02 06:07:31 [notice] 1#1: signal 2 (SIGINT) received, exiting
2022/06/02 06:07:31 [notice] 33#33: exiting
2022/06/02 06:07:31 [notice] 34#34: exiting
2022/06/02 06:07:31 [notice] 32#32: exiting
2022/06/02 06:07:31 [notice] 35#35: exiting
2022/06/02 06:07:31 [notice] 34#34: exit
2022/06/02 06:07:31 [notice] 33#33: exit
2022/06/02 06:07:31 [notice] 32#32: exit
2022/06/02 06:07:31 [notice] 35#35: exit
2022/06/02 06:07:31 [notice] 1#1: signal 17 (SIGCHLD) received from 35
2022/06/02 06:07:31 [notice] 1#1: worker process 32 exited with code 0
2022/06/02 06:07:31 [notice] 1#1: worker process 35 exited with code 0
2022/06/02 06:07:31 [notice] 1#1: signal 29 (SIGIO) received
2022/06/02 06:07:31 [notice] 1#1: signal 17 (SIGCHLD) received from 33
2022/06/02 06:07:31 [notice] 1#1: worker process 33 exited with code 0
2022/06/02 06:07:31 [notice] 1#1: signal 29 (SIGIO) received
2022/06/02 06:07:31 [notice] 1#1: signal 17 (SIGCHLD) received from 34
2022/06/02 06:07:31 [notice] 1#1: worker process 34 exited with code 0
2022/06/02 06:07:31 [notice] 1#1: exit

✨小写p:宿主机访问1111端口
在这里插入图片描述
✨大写P:宿主机访问49161端口(随机指定的)
在这里插入图片描述

🌏 目前存在的问题:1、启动nginx,终端会展示日志;2、一旦关闭终端,容器将停止工作。
解决:

🌙9、后台运行容器

-d:指定容器在后台执行
特别注意:如果是手动指定端口,需要将防火墙中的这个端口放通

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker run --name nginx_4 -P -d nginx
fa855451e519418cf4348a16dcaf52dcbd53e971bc934e196bdb3130acd72026

- -rm:退出容器后,会自动将容器删除

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker run -it --name centos_1 --rm centos
[root@f992808f12cc /]# exit
exit

🌙10、创建容器的时候指定环境变量

-e:设置全局变量

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker run --rm -it -e USERNAME=kobe -e PASSWORD=123123 centos /bin/bash
[root@0489627cb70f /]# env
LANG=en_US.UTF-8
HOSTNAME=0489627cb70f
USERNAME=kobe
PASSWORD=123123
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LESSOPEN=||/usr/bin/lesspipe.sh %s
_=/usr/bin/env


🌙11、进入正在运行中的容器

exec:进入正在运行中的容器

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker exec -it centos_1 /bin/bash
[root@7e1cf2a4bec7 /]# 

✨当容器太多时,查看需要的容器

zhilong@zhilong-virtual-machine:~/桌面$ sudo docker ps | awk '/Up/ {print $1,$NF}'
95cf126972d5 centos_2
7e1cf2a4bec7 centos_1
d992bc0fa330 nginx_test
2c4108268aa9 jenkins
ae1fd6dd1b00 mysql

🌙12、查看某个容器的进程

zhilong@zhilong-virtual-machine:~/桌面$ sudo docker top centos_1
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                52297               52276               0                   14:31               pts/0               00:00:00            /bin/bash
zhilong@zhilong-virtual-machine:~/桌面$ 

🌙13、查看容器资源利用率

CONTAINER ID   NAME       CPU %     MEM USAGE / LIMIT     MEM %     NET I/O       BLOCK I/O     PIDS
7e1cf2a4bec7   centos_1   0.00%     2.566MiB / 3.798GiB   0.07%     3.79kB / 0B   1.43MB / 0B   1

停止容器:sudo docker stop 容器id或者容器名称
重启容器:sudo docker restart 容器id或者容器名称
暂停容器:sudo docker paush 容器id或者容器名称
取消暂停容器:sudo docker unpaush 容器id或者容器名称
删除容器:sudo docker rm 容器id或者容器名称(前提是先暂停容器)
强制删除容器:sudo docker rm -f 容器id或者容器名称

二、网络

🌙1、网络类型:

✨bridge:

  • nat网络模型
  • 虚拟交换机

✨host

  • 与宿主机共享网络
  • –net=host

✨none

  • 不配置网络
  • –net=none

✨overlay

  • 不同网络进行通信

🌙2、查看容器的ip地址

sudo docker inspect nginx_1:查看容器的详细信息
sudo docker exec -it nginx_1 ip a:进入容器查看容器的ip
172.17.0.5

✨第一种方法:

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker exec -it nginx_1 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
112: eth0@if113: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP 
    link/ether 02:42:ac:11:00:05 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.5/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever


✨第二方法:

zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker inspect nginx_1 | grep "IPAddress"
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.5",
                    "IPAddress": "172.17.0.5",
zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker inspect nginx_2 | grep "IPAddress"
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.6",
                    "IPAddress": "172.17.0.6",
zhilong@zhilong-virtual-machine:~/Desktop/shell_text/docker$ sudo docker inspect nginx_3 | grep "IPAddress"
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.7",
                    "IPAddress": "172.17.0.7",


✨查看nginx_1、nginx_2、nginx_3三个容器的ip地址

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

er inspect nginx_3 | grep “IPAddress”
“SecondaryIPAddresses”: null,
“IPAddress”: “172.17.0.7”,
“IPAddress”: “172.17.0.7”,


**✨查看nginx\_1、nginx\_2、nginx\_3三个容器的ip地址**



[外链图片转存中...(img-CaDTFlCt-1715798677588)]
[外链图片转存中...(img-SIUjsUlE-1715798677588)]
[外链图片转存中...(img-lyPozeV2-1715798677588)]

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值