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项目
相关推荐
Narutolxy15 分钟前
Ubuntu 下 Docker 企业级运维指南:核心命令与最佳实践深度解析20250309
运维·ubuntu·docker
明明跟你说过37 分钟前
在【k8s】中部署Jenkins的实践指南
运维·ci/cd·云原生·容器·kubernetes·jenkins
酥暮沐40 分钟前
K8S 集群搭建——cri-dockerd版
linux·容器·kubernetes
a_j5843 分钟前
k8s面试题总结(十)
云原生·容器·kubernetes
沉默的八哥1 小时前
RBAC的工作原理,以及如何限制特定用户访问
运维·kubernetes
琪琪花2 小时前
sshfs 将远程服务器上的文件系统挂载到本地目录
linux·运维·服务器
Yuanymoon2 小时前
【由技及道】镜像星门开启:Harbor镜像推送的量子跃迁艺术【人工智障AI2077的开发日志010】
java·docker·jenkins·harbor·devops
wayuncn2 小时前
哈尔滨服务器租用的流程
运维·服务器
blasit4 小时前
keil 5 MDK 安装失败提示Cannot create destination file."文件名、目录名或卷标语法不正确"
运维·程序员·如何当个好爸爸
fanxiaohui121384 小时前
元脑服务器的创新应用:浪潮信息引领AI计算新时代
运维·服务器·人工智能