docker下拉(pull)镜像和生成容器,文章尾部有常用的linux命令

目录

1:docker镜像和容器是什么

2:docker初始化个容器,并进入容器安装mariaDb和httpd

1:用远程工具SecureCRT登录docker

2:拉取CentOS镜像并初始化一个容器

a:拉取镜像(这一步可能会有点久)

b:查看镜像

[c:生成容器(我命名为centos74 ,镜像名centos )](#c:生成容器(我命名为centos74 ,镜像名centos ))

d:进入容器

3:安装MariaDB

1:查询有没有安装过mariaDB

2:删除安装的mariaDB

3:更改数据源,用yum安装

4:安装httpd

5:安装php

3:测试端口可不可以访问

4:敲黑板

[5:下一章使用spring boot的搭建安全的后台maven项目](#5:下一章使用spring boot的搭建安全的后台maven项目)


先说说这篇文章看完你能学习到什么吧

复制代码
1:docker镜像和容器是什么,2:docker初始化个容器,并进入容器安装mariaDb和httpd和php,3:测试端口可不可以访问,4:敲黑板
1:docker镜像和容器是什么

docker镜像是一个集成可运行环境的快照。而docker容器是一个可运行的载体。可以说一个镜像可以生成多个容器,镜像是基础,容器是多态。我们可以自己生成镜像,并上传到docker官网(Docker: Accelerated Container Application Development),然后通过docker pull命令进行领取。

2:docker初始化个容器,并进入容器安装mariaDb和httpd
1:用远程工具SecureCRT登录docker

主机地址192.168.99.100

用户名:docker

密码: tcuser

2:拉取CentOS镜像并初始化一个容器
a:拉取镜像(这一步可能会有点久)

docker pull centos

b:查看镜像

docker images查询所有镜像,这里会列出所有的镜像信息,包扣镜像id,镜像名。你可以通过容器id或者容器名启动镜像。

c:生成容器(我命名为centos74 ,镜像名centos )

docker run -d -p 5000:22 -p 8888:80 --name centos74 --privileged=true centos /usr/sbin/init

c->1:这里的-p后面是端口映射,例如5000:22是把容器的22端口映射到宿主机的5000,也就是我们可以通过5000访问到容器的22

c->2:启动这步可能会遇到的问题

c->2:1: cgroups: cannot find cgroup mount destination: unknown.

解决这个问题:

在docker生成容器前运行:

docker run --privileged=true

sudo mkdir /sys/fs/cgroup/systemd

sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd

c->2:2:/usr/bin/docker-current: Error response from daemon: driver failed programmi

解决这个问题:重启docker

d:进入容器

docker exec -it centos74 /bin/bash

3:安装MariaDB
1:查询有没有安装过mariaDB

rpm -qa | grep Maria*

2:删除安装的mariaDB

yum -y remove mari*

3:更改数据源,用yum安装

a:vim /etc/yum.repos.d/mariadb.repo(国外的源太慢了,我用了国内的,参考下http://mirrors.ustc.edu.cn/help/mariadb.html)

b:插入以下内容保存(也可以自己去寻找适合的版本https://downloads.mariadb.org/mariadb/repositories/#distro=CentOS\&distro_release=centos7-ppc64le--centos7\&version=10.3)

MariaDB 10.2 CentOS repository list - created 2017-07-03 06:59 UTC

http://downloads.mariadb.org/mariadb/repositories/

mariadb

name = MariaDB

baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64

gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB

gpgcheck=1

c :开始安装

yum install MariaDB-server MariaDB-client

d:启动

systemctl start mysql

e:mysql -uroot -p输入密码

4:安装httpd

yum install httpd

systemctl start httpd

5:安装php

yum install php

yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

systemctl restart httpd

3:测试端口可不可以访问

vi /var/www/html/info.php

<?php

phpinfo();

?>

24:访问

http://192.168.99.100:8888/info.php

4:敲黑板

1:端口映射除了初始化容器-p 5000 22这种方式还有其他方法吗?

答:有的,可以在进入容器后运行

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 9000 -j DNAT --to-destination 172.17.0.2:9000

这里的172.17.0.2:9000是容器的端口,前面的9000是映射到宿主机的端口。

2:linux的常用命令有哪些

答:

a:全局查找文件命令

find / -name pp.txt

b:日志滚动查看命令

tail -f xx.log

c:后台挂载启动程序名

nohup java -jar xx.jar &

d:查询类型任务状态

ps -ef | grep java

e:centos7启动和状态和停止服务的命令

systemctl status mysql

systemctl start mysql

systemctl top mysql

f:安装命令

yum install mysql

wget https://ftp.gnu.org/gnu/wget/wget-1.21.2.tar.gz

g:解压

tar -xzvf wget-1.21.2.tar.gz

h:编译

./configure

i:安装

make

j:查询服务所在路径

whereis httpd

k:添加环境变量

vim /etc/profile

添加一下内容:

export MONGODB_HOME=/usr/local/mongodb

export PATH=MONGODB_HOME/bin:PATH

让属性生效

source /ect/profile

l:设置redis进行systemctl启动

1,在 /etc/systemd/system 下新建redis.service,并添加一下内容:

注意修改 /usr/local/redis-6.2.1/src 为你自定义安装的redis目录。

Unit

Description=Redis

After=network.target

Service

Type=forking

ExecStart=/usr/local/redis-6.2.1/src/redis-server /usr/local/redis-6.2.1/redis.conf

ExecReload=/usr/local/redis-6.2.1/src/redis-server -s reload

ExecStop=/usr/local/redis-6.2.1/src/redis-server -s stop

PrivateTmp=true

Install

WantedBy=multi-user.target

2,systemctl daemon-reload # 加载服务配置文件

3,然后systemctl start redis启动即可。

m:设置mongo,systemctl启动(原理同上)

Unit

Description=mongodb

After=network.target remote-fs.target nss-lookup.target

Service

Type=forking

ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/etc/mongodb.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/etc/mongodb.conf --shutdown

PrivateTmp=true

Install

WantedBy=multi-user.target

5:下一章使用spring boot的搭建安全的后台maven项目
相关推荐
虎头金猫3 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
分布式存储与RustFS3 天前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
AI职业加油站3 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
此冬歌咏3 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
玉&心3 天前
通过Arthas在线诊断K8S中的内存及JVM等使用情况
docker·k8s·arthas
xing-xing3 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
-梅3 天前
linux(8) 软硬链接
linux·运维·服务器
赵文宇(温玉)3 天前
CoreDNS的hosts插件的缺行配置导致k8s集群异常
容器·kubernetes·rancher
guo_wen_qiang3 天前
上传本地镜像到harbor中
docker·容器·持续部署
张洛闻Eren3 天前
k8s云原生【第十课】:水平 Pod 自动扩缩容
运维·数据库·云原生·kubernetes·github