Docker实例

华子目录

  • docker实例
    • 1.为Ubuntu镜像添加ssh服务
    • 2.Docker安装mysql

docker实例

1.为Ubuntu镜像添加ssh服务

(1)访问https://hub.docker.com,寻找合适的Ubuntu镜像
在这里插入图片描述
(2)拉取Ubuntu镜像

[root@server ~]# docker pull ubuntu:latest
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest[root@server ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       latest    ba6acccedd29   2 years ago   72.8MB

(3)后台运行容器,并配置软件源

  • Ubuntu的软件源必须以.list结尾,并且软件源放在/etc/apt/
[root@server ~]# docker run -itd --name ubuntu -p 2222:22 ubuntu:latest
871fe7e0e9a3c0d3f5d079911483cb890323d2dfd3c13d23f685aa2dd4c75944
[root@server ~]# docker exec -it ubuntu bash
root@871fe7e0e9a3:/# mv /etc/apt/sources.list /etc/apt/sources.list.backup  #将原来的软件源置为备份root@871fe7e0e9a3:~# echo  deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse  >>  /etc/apt/sources.list
root@871fe7e0e9a3:~# echo  deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse  >>  /etc/apt/sources.list
root@871fe7e0e9a3:~# echo  deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse  >>  /etc/apt/sources.list
root@871fe7e0e9a3:~# echo  deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse  >>  /etc/apt/sources.list
root@871fe7e0e9a3:~# echo  deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse  >>  /etc/apt/sources.list
root@871fe7e0e9a3:~# echo  deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse  >>  /etc/apt/sources.list
root@871fe7e0e9a3:~# echo  deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse  >>  /etc/apt/sources.list
root@871fe7e0e9a3:~# echo  deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse  >>  /etc/apt/sources.listroot@871fe7e0e9a3:~# cd /etc/apt
root@871fe7e0e9a3:/etc/apt# ls
apt.conf.d  auth.conf.d  preferences.d  sources.list  sources.list.backup  sources.list.d  trusted.gpg.droot@871fe7e0e9a3:/etc/apt# apt update
Ign:1 https://mirrors.aliyun.com/ubuntu jammy InRelease
Ign:2 https://mirrors.aliyun.com/ubuntu jammy-security InRelease
Ign:3 https://mirrors.aliyun.com/ubuntu jammy-updates InRelease
Ign:4 https://mirrors.aliyun.com/ubuntu jammy-backports InRelease
Err:5 https://mirrors.aliyun.com/ubuntu jammy ReleaseCertificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown.  Could not handshake: Error in the certificate verification. [IP: 182.40.60.234 443]
Err:6 https://mirrors.aliyun.com/ubuntu jammy-security ReleaseCertificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown.  Could not handshake: Error in the certificate verification. [IP: 182.40.60.234 443]
Err:7 https://mirrors.aliyun.com/ubuntu jammy-updates ReleaseCertificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown.  Could not handshake: Error in the certificate verification. [IP: 182.40.60.234 443]
Err:8 https://mirrors.aliyun.com/ubuntu jammy-backports ReleaseCertificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown.  Could not handshake: Error in the certificate verification. [IP: 182.40.60.234 443]
Reading package lists... Done
W: https://mirrors.aliyun.com/ubuntu/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu/dists/jammy-security/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu/dists/jammy-updates/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu/dists/jammy-backports/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu/dists/jammy/Release: No system certificates available. Try installing ca-certificates.
E: The repository 'https://mirrors.aliyun.com/ubuntu jammy Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: https://mirrors.aliyun.com/ubuntu/dists/jammy-security/Release: No system certificates available. Try installing ca-certificates.
E: The repository 'https://mirrors.aliyun.com/ubuntu jammy-security Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: https://mirrors.aliyun.com/ubuntu/dists/jammy-updates/Release: No system certificates available. Try installing ca-certificates.
E: The repository 'https://mirrors.aliyun.com/ubuntu jammy-updates Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: https://mirrors.aliyun.com/ubuntu/dists/jammy-backports/Release: No system certificates available. Try installing ca-certificates.
E: The repository 'https://mirrors.aliyun.com/ubuntu jammy-backports Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

(4)安装和配置ssh服务

root@871fe7e0e9a3:~# apt install openssh-server -y

(5)如果需要正常启动ssh服务,则目录/var/run/sshd必须存在

root@871fe7e0e9a3:~# mkdir -p /var/run/sshd

(6)启动ssh服务,并查看监听状态

root@871fe7e0e9a3:~# /usr/sbin/sshd -D &
root@871fe7e0e9a3:~# apt install iproute
root@871fe7e0e9a3:~# ss -lntup

(7)使用ssh连接容器

[root@node1 ~]# ssh root@192.168.80.129 -p 2222

2.Docker安装mysql

(1)访问https://hub.docker.com,寻找合适的mysql镜像
在这里插入图片描述
(2)拉取mysql镜像

[root@server ~]# docker pull mysql:latest
latest: Pulling from library/mysql
72a69066d2fe: Pull complete
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
688ba7d5c01a: Pull complete
00e060b6d11d: Pull complete
1c04857f594f: Pull complete
4d7cfa90e6ea: Pull complete
e0431212d27d: Pull complete
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest[root@server ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
mysql        latest    3218b38490ce   2 years ago   516MB
ubuntu       latest    ba6acccedd29   2 years ago   72.8MB

(3)后台运行容器,并使用exec进入容器

  • mariadbMySQL指定-e变量时都是MYSQL_ROOT_PASSWORD
[root@server ~]# docker run -itd --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:latest
ea6beb680b7ae725d844bd3360e184e772bbbadc9df1e84f10a90b60a9625c52
[root@server ~]# docker ps
CONTAINER ID   IMAGE           COMMAND                   CREATED          STATUS          PORTSNAMES
ea6beb680b7a   mysql:latest    "docker-entrypoint.s…"   15 seconds ago   Up 14 seconds   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
871fe7e0e9a3   ubuntu:latest   "bash"                    44 minutes ago   Up 44 minutesubuntu
[root@server ~]# docker exec -it mysql bash
root@ea6beb680b7a:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 MySQL Community Server - GPLCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/589172.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

矽塔SA6184 产品说明书

集成 70V 6N 三相栅极驱动及 5V 和 12V LDO 控制芯片 描述 SA6184是一款集成了70V耐压的三个独立半桥栅极驱动,自举二极管,5V LDO和12V LDO控制电路的控制芯片,适合于12V,24V和多节锂电池供电应用中三相电机应用中高速功率MOSFET 和IGBT的栅…

Spring IOC控制反转、DI注入以及配置

1.使用xml的方式进行配置IOC容器&#xff0c;首先引入依赖 在Resource资源下配置&#xff0c;applicationContext.xml ,刷新mevan后可以直接选择配置spring.xml文件 <!-- spring核心用来管理bean --><dependency><groupId>org.springframework</g…

是什么引起LED显示屏发生故障?

LED显示屏作为一种高科技的显示解决方案&#xff0c;虽然具有许多优势&#xff0c;但在使用过程中也可能会出现故障。了解引起LED显示屏故障的因素&#xff0c;对于预防问题和及时维修至关重要。以下是一些常见的导致LED显示屏发生故障的原因&#xff1a; 电源问题&#xff1a;…

设计模式12--组合模式

定义 案例一 案例二 优缺点

C++:命名空间namescape,缺省参数

文章目录 1.命名空间namescape1.1命名空间namescape定义1.2命名空间namescape规则 2.2 命名空间使用3 C输入&输出4. 缺省参数 1.命名空间namescape 在C/C中&#xff0c;变量、函数和后面要学到的类都是大量存在的&#xff0c;这些变量、函数和类的名称将都存在于全局作用域…

烂笔头笔记:Windows 11下照片查看器显示偏色问题修复

本文出处&#xff1a;http://blog.csdn.net/chaijunkun/article/details/137278931&#xff0c;转载请注明。由于本人不定期会整理相关博文&#xff0c;会对相应内容作出完善。因此强烈建议在原始出处查看此文。 最近在研究HDR视频的截图算法&#xff0c;目的就是生成色彩正确…

【JavaWeb】Day25.Web入门——HTTP协议(一)

HTTP协议——概述 1.介绍 HTTP&#xff1a;Hyper Text Transfer Protocol(超文本传输协议)&#xff0c;规定了浏览器与服务器之间数据传输的规则。 http是互联网上应用最为广泛的一种网络协议http协议要求&#xff1a;浏览器在向服务器发送请求数据时&#xff0c;或是服务器在…

华为数通方向HCIP-DataCom H12-821题库(多选题:261-280)

第261题 VRRP可以结合以下哪些机制或技术来监视上行链路的连通性? A、IP-Link B、BFD C、NQA D、接口Track 【正确答案】BCD 【答案解析】 第262题 以下关干RSTP根保护的说法正确的是? A、根端口上开启根保护功能会生效 B、开启根保护的端口再收到优先级更高的RSTBPDU之后如…

经典文献阅读之--i-Octree(用于最近邻搜索的快速、轻量级和动态的八叉树)

0. 简介 在众多机器人应用中&#xff0c;通过最近邻搜索建立新采集点与历史累积数据&#xff08;即地图&#xff09;之间的对应关系至关重要。然而&#xff0c;静态树数据结构不足以实时处理大型且动态增长的地图。为了解决这个问题&#xff0c;我们在文中《i-Octree: A Fast,…

HarmonyOS NEXT应用开发之MVVM模式

应用通过状态去渲染更新UI是程序设计中相对复杂&#xff0c;但又十分重要的&#xff0c;往往决定了应用程序的性能。程序的状态数据通常包含了数组、对象&#xff0c;或者是嵌套对象组合而成。在这些情况下&#xff0c;ArkUI采取MVVM Model View ViewModel模式&#xff0c;其…

使用deepspeed小记

1. 减少显存占用的历程忠告 医学图像经常很大&#xff0c;所以训练模型有时候会有难度&#xff0c;但是现在找到了很多减少显存的方法。 不知道为什么&#xff0c;使用transformers的trainer库确确实实会减少显存的占用&#xff0c;即使没有使用deepspeed&#xff0c;占用的显…

nginx与tomcat的区别?

关于nginx和tomcat的概念 网上有很多关于nginx和tomcat是什么东西的定义&#xff0c;我总结了一下: tomcat是Web服务器、HTTP服务器、应用服务器、Servlet容器、web容器。 Nginx是Web服务器、HTTP服务器、正向/反向代理服务器&#xff0c;。 这里有两个概念是交叉的&#xff…