本文主要是介绍8.22-docker的部署及其使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
docker
1.docker环境部署以及语法
[root@docker ~]# cat << EOF | tee /etc/modules-load.d/k8s.conf> overlay> br_netfilter> EOFoverlaybr_netfilter[root@docker ~]# modprobe overlay[root@docker ~]# modprobe br_netfilter[root@docker ~]# cat /etc/modules-load.d/k8s.confoverlaybr_netfilter[root@docker ~]# sysctl --system[root@docker ~]# yum -y install yum-utils device-mapper-persistent-data lvm2# 配置一个仓库[root@docker ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo[root@docker ~]# ls /etc/yum.repos.d/CentOS-Base.repo docker-ce.repo epel.repo epel-testing.repo haha.repo[root@docker ~]# yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y# 启动服务[root@docker ~]# systemctl start docker[root@docker ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE# 搜索镜像[root@docker ~]# docker search tomcat# 配置docker守护进程[root@docker ~]# vim /etc/docker/daemon.json{"registry-mirrors": ["https://do.nark.eu.org","https://dc.j8.work","https://docker.m.daocloud.io","https://dockerproxy.com","https://docker.mirrors.ustc.edu.cn","https://docker.nju.edu.cn"][root@docker ~]# systemctl restart docker# 下载centos镜像[root@docker ~]# docker pull centos# 开启服务[root@docker ~]# systemctl start docker.service# 查看镜像[root@docker ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos latest 5d0da3dc9764 2 years ago 231MB# -i 允许交互 -t终端运行[root@docker ~]# docker run -i -t --name=c1 centos:latest /bin/bash[root@21d6b0b5e067 /]# lsbin etc lib lost+found mnt proc run srv tmp vardev home lib64 media opt root sbin sys usr[root@21d6b0b5e067 /]# cd /etc/yum.repos.d/[root@21d6b0b5e067 yum.repos.d]# lsCentOS-Linux-AppStream.repo CentOS-Linux-FastTrack.repoCentOS-Linux-BaseOS.repo CentOS-Linux-HighAvailability.repoCentOS-Linux-ContinuousRelease.repo CentOS-Linux-Media.repoCentOS-Linux-Debuginfo.repo CentOS-Linux-Plus.repoCentOS-Linux-Devel.repo CentOS-Linux-PowerTools.repoCentOS-Linux-Extras.repo CentOS-Linux-Sources.repo# 不能查看ip(容器)[root@21d6b0b5e067 yum.repos.d]# ifconfigbash: ifconfig: command not found[root@21d6b0b5e067 yum.repos.d]# cd# 配置阿里云的仓库[root@21d6b0b5e067 /]# rm -rf /etc/yum.repos.d/* [root@21d6b0b5e067 /]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed100 2495 100 2495 0 0 464 0 0:00:05 0:00:05 --:--:-- 637[root@21d6b0b5e067 /]# ls /etc/yum.repos.d/CentOS-Base.repo# 清除缓存,建立缓存[root@21d6b0b5e067 /]# yum clean all && yum makecache# 安装httpd和net-tools[root@21d6b0b5e067 /]# yum -y install httpd[root@21d6b0b5e067 /]# yum -y install net-tools# 可以查到ip地址[root@21d6b0b5e067 /]# ifconfigeth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)RX packets 10539 bytes 17122684 (16.3 MiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 7348 bytes 404167 (394.6 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@21d6b0b5e067 /]# psPID TTY TIME CMD1 pts/0 00:00:00 bash71 pts/0 00:00:00 ps[root@21d6b0b5e067 /]# uptime06:33:36 up 3:35, 0 users, load average: 0.06, 0.05, 0.05[root@21d6b0b5e067 /]# pwd/# 查看版本信息[root@21d6b0b5e067 /]# cat /etc/redhat-release CentOS Linux release 8.4.2105# 修改资源文件[root@21d6b0b5e067 /]# echo "docker_httpd_server" > /var/www/html/index.html# 启动服务(启动失败)--内存太小[root@21d6b0b5e067 /]# systemctl start httpdSystem has not been booted with systemd as init system (PID 1). Can't operate.Failed to connect to bus: Host is down# 手动启动[root@21d6b0b5e067 /]# httpd -k startAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message# 在容器里可以访问到内容[root@21d6b0b5e067 /]# curl localhostdocker_httpd_server[root@21d6b0b5e067 /]# curl http://localhost:80docker_httpd_server# 在配置c1容器的主机里也可以访问到内容[root@docker ~]# curl http://172.17.0.2:80docker_httpd_server# 外界浏览器访问不到内容
2.docker创建容器的语法
3.退出以及重进容器
# 如果没有指令正在运行,容器就会停止[root@21d6b0b5e067 /]# exitexit[root@docker ~]# curl 172.17.0.2^C[root@docker ~]# ssh root@172.17.0.2ssh: connect to host 172.17.0.2 port 22: No route to host# 退出c1镜像后也可以继续进到容器中# 重启容器[root@docker ~]# docker start c1c1# 将c1容器的终端附加到docker主机上[root@docker ~]# docker attach c1# 这个时候,httpd服务又停了[root@21d6b0b5e067 /]# netstat -lntup|grep 80# 启动服务[root@21d6b0b5e067 /]# httpd -k startAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message# 可以访问[root@21d6b0b5e067 /]# curl localhostdocker_httpd_server# 退出容器服务不中断-按ctrl+p+q键[root@21d6b0b5e067 /]systemctl start httpdread escape sequence[root@docker ~]# curl 172.17.0.2docker_httpd_server
4.远程管理
# 检查状态# 查看套接字文件[root@docker ~]# ls -lh /var/run/srw-rw----. 1 root docker 0 8月 22 11:44 docker.sock# 要允许远程连接,需要有一个服务,使用端口[root@docker ~]# systemctl start docker[root@docker ~]# netstat -lntup|grep 2375[root@docker ~]# ls -lh /var/run/# 设置允许远程管理# 停止docker服务[root@docker ~]# vim /usr/lib/systemd/system/docker.service # 删除13行dockerd后面的内容13 ExecStart=/usr/bin/dockerd# 修改daemon.json文件[root@docker ~]# vim /etc/docker/daemon.json {"registry-mirrors": ["https://do.nark.eu.org","https://dc.j8.work","https://docker.m.daocloud.io","https://dockerproxy.com","https://docker.mirrors.ustc.edu.cn","https://docker.nju.edu.cn"],"hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"]}# 加载daemon.json文件[root@docker ~]# systemctl daemon-reload# 启动服务[root@docker ~]# systemctl start docker[root@docker ~]# netstat -lntup|grep 2375tcp6 0 0 :::2375 :::* LISTEN 6321/dockerd # 查看套接字文件[root@docker ~]# ls -lh /var/run/srw-rw----. 1 root docker 0 8月 22 16:10 docker.sock# 远程管理[root@docker ~]# docker -H 192.168.2.30 imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos latest 5d0da3dc9764 2 years ago 231MB
这篇关于8.22-docker的部署及其使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!