首页 > 其他分享 >Docker学习使用01

Docker学习使用01

时间:2023-01-07 21:33:42浏览次数:63  
标签:Pull 01 complete 学习 nginx home Docker root docker

安装

官网地址:https://docs.docker.com/engine/install/centos/

1.卸载旧版本

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

2.需要的安装包

yum install -y yum-utils

3.设置镜像的仓库

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
## 上面这个是外网的地址,可能会很慢,建议用国内的镜像
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
## 建议用下面阿里的
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

4.更新yum软件包索引

yum makecache fast

5.安装docker

yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

6.启动docker

systemctl start docker

7.查看docker version

docker version

7.hello-world

docker run hello-world
## 没有hello-world镜像回去拉取

8.查看hello-world镜像

docker images

卸载

yum remove docker-ce docker-ce-cli containerd.io docker-compose-plugin
rm -rf /var/lib/docker
rm -rf /var/lib/containerd

Docker 命令

https://docs.docker.com/engine/reference/run/

帮助命令

docker version
docker info
docker 命令 --help 

镜像命令

查看镜像 docker images

docker images [OPTIONS] [REPOSITORY[:TAG]]
#参数 -a 显示所有
#参数 -q 只显示id

docker search mysql --filter=stars=5000
# 查询关键字mysql,过滤条件为Stars不区分大小写,5000以上的

下载镜像 docker pull

docker pull mysql
Using default tag: latest #默认标签使用
latest: Pulling from library/mysql
0ed027b72ddc: Pull complete #分层下载
0296159747f1: Pull complete 
3d2f9b664bd3: Pull complete 
df6519f81c26: Pull complete 
36bb5e56d458: Pull complete 
054e8fde88d0: Pull complete 
f2b494c50c7f: Pull complete 
132bc0d471b8: Pull complete 
135ec7033a05: Pull complete 
5961f0272472: Pull complete 
75b5f7a3d3a4: Pull complete 
Digest: sha256:3d7ae561cf6095f6aca8eb7830e1d14734227b1fb4748092f2be2cfbccf7d614 #签名
Status: Downloaded newer image for mysql:latest 
docker.io/library/mysql:latest #实际地址

########################################################
docker pull mysql
#等价于
docker pull docker.io/library/mysql:latest

删除镜像 docker rmi -f [imagesid]

docker rmi -f $(docker images -aq)

容器命令

说明:我们有了镜像才可以创建容器,linux,下载一个centos镜像来测试学习

docker pull centos

新建容器并启动

docker run [可选参数] image
# 参数说明
--name="Name" 容器名字 
-d            后台运行方式
-it           使用交互方式运行,进入容器查看内容
-p            指定容器的端口 -p 主机端口:容器端口
-P            随机指定端口

启动并进入容器

[root@iZ8vb9gbgzbq4vx5w96rj7Z ~]# docker run -it centos /bin/bash 
[root@7e491d32442c /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

退出容器,停止运行

exit

退出容器,不停止运行

Ctrl+P+Q

列出所有容器

docker ps
docker ps -a # 列出所有容器,包括已停止的

删除容器

docker rm 容器id 
docker rm -f $(docker ps -aq)   #-f为强制删除
docker ps -a -q|xargs docker rm #删除所有容器

启动和停止容器

docker start 容器id
docker stop 容器id
docker restart 容器id
docker kill 容器id

其他命令

查看日志

docker logs -f -t --tail 10 容器id

查看进程信息

docker top 容器id

查看镜像元数据

docker inspect 容器id

进入当前正在运行的容器

docker exec -it 容器id bashShell
docker exec -it 7e491d32442c /bin/bash

docker attach 容器id
docker attach 7e491d32442c

拷贝容器内文件

注意,容器不运行也没有关系

docker cp 容器id:容器path   

[root@7e491d32442c /]# cd home 
[root@7e491d32442c home]# touch test.java
[root@7e491d32442c home]# ls
test.java
[root@7e491d32442c home]# lsread escape sequence
[root@iZ8vb9gbgzbq4vx5w96rj7Z ~]# docker cp 7e491d32442c:/home/test.java /home
[root@iZ8vb9gbgzbq4vx5w96rj7Z ~]# ls
1.txt  test1  tool
[root@iZ8vb9gbgzbq4vx5w96rj7Z ~]# cd /home
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# ls
jdk-8u202-linux-x64.rpm  temp  test.java  website
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# 

实例

安装nginx

[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# docker search nginx
NAME                                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                                             Official build of Nginx.                        17913     [OK]       
linuxserver/nginx                                 An Nginx container, brought to you by LinuxS…   181                  
bitnami/nginx                                     Bitnami nginx Docker Image                      149                  [OK]
ubuntu/nginx                                      Nginx, a high-performance reverse proxy & we…   73                   
bitnami/nginx-ingress-controller                  Bitnami Docker Image for NGINX Ingress Contr…   23                   [OK]
rancher/nginx-ingress-controller                                                                  11                   
kasmweb/nginx                                     An Nginx image based off nginx:alpine and in…   4                    
ibmcom/nginx-ingress-controller                   Docker Image for IBM Cloud Private-CE (Commu…   4                    
bitnami/nginx-exporter                                                                            3                    
bitnami/nginx-ldap-auth-daemon                                                                    3                    
rancher/nginx                                                                                     2                    
circleci/nginx                                    This image is for internal use                  2                    
rancher/nginx-ingress-controller-defaultbackend                                                   2                    
rapidfort/nginx                                   RapidFort optimized, hardened image for NGINX   2                    
vmware/nginx                                                                                      2                    
vmware/nginx-photon                                                                               1                    
bitnami/nginx-intel                                                                               1                    
wallarm/nginx-ingress-controller                  Kubernetes Ingress Controller with Wallarm e…   1                    
rapidfort/nginx-ib                                RapidFort optimized, hardened image for NGIN…   0                    
rancher/nginx-conf                                                                                0                    
rapidfort/nginx-official                          RapidFort optimized, hardened image for NGIN…   0                    
ibmcom/nginx-ppc64le                              Docker image for nginx-ppc64le                  0                    
rancher/nginx-ssl                                                                                 0                    
ibmcom/nginx-ingress-controller-ppc64le           Docker Image for IBM Cloud Private-CE (Commu…   0                    
continuumio/nginx-ingress-ws                                                                      0                    
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
3f4ca61aafcd: Pull complete 
50c68654b16f: Pull complete 
3ed295c083ec: Pull complete 
40b838968eea: Pull complete 
88d3ab68332d: Pull complete 
5f63362a3fa3: Pull complete 
Digest: sha256:0047b729188a15da49380d9506d65959cce6d40291ccfb4e039f5dc7efd33286
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# docker run -d --name nginx01 -p 8080:80 nginx
c6e16eb5fde2a687d8c4b41cc2bb5d2bb8f425ac142f1f687b15cb4f9794e292
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# curl localhost:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# 

安装tomcat

[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# docker pull tomcat:9.0
9.0: Pulling from library/tomcat
6e3729cf69e0: Pull complete 
4d8d923227d8: Pull complete 
eda8241fd25f: Pull complete 
35dccabde73d: Pull complete 
978c906bcdda: Pull complete 
542de2e3d783: Pull complete 
3294a3c6321f: Pull complete 
Digest: sha256:39cb3ef7ca90051f969c58137b9439eb2e81fcfca38f1d09f9cb5ca3d1b7bc93
Status: Downloaded newer image for tomcat:9.0
docker.io/library/tomcat:9.0
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
nginx         latest    1403e55ab369   2 weeks ago     142MB
tomcat        9.0       24849d4d07c1   4 weeks ago     476MB
mysql         latest    7484689f290f   4 weeks ago     538MB
hello-world   latest    feb5d9fea6a5   15 months ago   13.3kB
centos        latest    5d0da3dc9764   15 months ago   231MB
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# docker run -d -p 8081:8080 --name tomcat01 tomcat:9.0
bb5e2e32b8c76ee0e47fecb5532413a5e103b62645878947c455f534b4723c9f
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# curl localhost:8081
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/9.0.70</h3></body></html>[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# 

安装ES

# 注意需要加内存限制,不然内存太小可能直接崩掉
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# docker run -d --name elasticsearch3  -p 9200:9200 -p9300:9300 -e"discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m"  elasticsearch:7.6.2
59c49905ad53dff5ceaf82385a03383988e7cd121271d2f488c7fe2bf2828e54
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS                                            NAMES
59c49905ad53   elasticsearch:7.6.2   "/usr/local/bin/dock…"   11 seconds ago   Up 10 seconds   0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   elasticsearch3
bb5e2e32b8c7   tomcat:9.0            "catalina.sh run"        29 minutes ago   Up 29 minutes   0.0.0.0:8081->8080/tcp                           tomcat01
c6e16eb5fde2   nginx                 "/docker-entrypoint.…"   44 minutes ago   Up 44 minutes   0.0.0.0:8080->80/tcp                             nginx01
0b0c75786a4c   centos                "/bin/bash"              3 hours ago      Up 3 hours                                                       silly_kirch
7e491d32442c   centos                "/bin/bash"              4 hours ago      Up 3 hours                                                       elastic_torvalds
[root@iZ8vb9gbgzbq4vx5w96rj7Z home]# curl localhost:9200
{
  "name" : "59c49905ad53",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "GNQzypIZTs6GOGkfSw2EKw",
  "version" : {
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

可视化

Portainer

docker run -d -p 8088:9000 \
--restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer

Rancher (CI/CD再用)

标签:Pull,01,complete,学习,nginx,home,Docker,root,docker
From: https://www.cnblogs.com/huacha/p/17029259.html

相关文章

  • 一些学习编程的优质网站
    国外的google.com就不说了,好是好,得跳墙。http://github.com地球上最大的开源中心,项目非常丰富,从华贵绚丽的界面到低调实用的小类库,应有尽有。需要睁大眼睛慢慢挑,适合......
  • JavaScript学习笔记—声明
    (1)变量声明提前使用var关键字声明的变量,会在所有代码执行前被声明(但不会赋值)console.log("a="+a);//a已声明,但是值是undefinedvara=123;如果声明变量时不使用v......
  • JavaScript学习笔记—this的使用
      解析器调用函数时每次都会向函数传递进一个隐含的参数this,this指向的是一个对象,这个对象称为函数执行的上下文对象。  根据函数的调用方式不同,this会指向不同的对象......
  • JavaScript学习笔记—对象的方法
    对象的属性值可以是任何的数据类型,也可以是个函数如果函数作为对象的属性保存,那这个函数是这个对象的方法,调用函数就是调用对象的方法varobj=newObject();//向对象......
  • 第一天开始学习Java--准备工作
    注册博客园养成一个做笔记的好习惯Markdown学习--Typora标题--(#+空格+标题)几个#表示几级标题(最多六个)字体粗体:**字体**斜体:*字体*斜体加粗:字体(两边三个*)删除......
  • 学习笔记——书城项目之“我的订单”功能
    2023-01-07一、“我的订单”功能(1)找到“我的订单”的位置①购物车页面Cart.html中的第26行②结算完成页面Checkout.html中的第45行将两个位置中超链接的“href”改变......
  • nvidia-rapids (cuML)机器学习加速库安装和使用
    背景:sklearn是非常成熟、使用方便的机器学习算法工具包,但是其运行速度慢,只能支持CPU运行,一直是一个诟病。现在也出现了对sklearn中算法加速的工具包,比如thundersvm、skl......
  • JavaScript学习笔记—函数的参数
    (1)如果实参的数量少于形参的数量,则没有对应实参的形参将是undefined//函数,a和b叫形参functionsum(a,b){console.log("a="+a);console.log("b="+b);consol......
  • SpringBoot基础学习二
    45、web实验-抽取公共页面官方文档-TemplateLayout公共页面/templates/common.html<!DOCTYPEhtml><htmllang="en"xmlns:th="http://www.thymeleaf.org"><!--注......
  • JavaScript学习笔记—基本数据类型和引用数据类型
    基本数据类型:String、Number、Boolean、Null、Undefined引用数据类型:ObjectJS中的变量都是保存到栈内存中的  基本数据类型的值直接在栈内存中存储,值与值之间是独立......