Docker--安装步骤笔记
第一步:打开虚拟机设置,设置虚拟光驱指定镜像。第二步:安装 :启动虚拟机,选择第一个安装。第一步:VM中虚拟机添加一块10G硬盘。容器,并打印出当前系统时间。rhel8.9镜像文件。
·
一、环境准备
VM网络配置
- 打开VMware软件 --编辑 --虚拟网络编辑器
二、VM创建虚拟机
三、安装rhel8.9操作系统
1、rhel8.9 镜像下载
- 第一步:进入redhat官网进行注册
- 第二步:下载rhel8.9镜像文件 https://access.redhat.com/downloads/content/rhel
2、操作系统安装
- 第一步:打开虚拟机设置,设置虚拟光驱指定镜像iso文件
- 第二步:安装 :启动虚拟机,选择第一个安装
- 安装语言,English
- 配置四个选项:
- 安装目的地:默认- 时区:亚洲 -上海- 软件选择:最小化安装- Root 密码: 123456
3、系统-网络配置
- 第一步:网卡ip地址配置
IP : 10.0.0.2子网: 255.255.255.0网关: 10.0.0.254
编辑网卡配置文件
# vi /etc/sysconfig/network-scripts/网卡文件
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
NAME=网卡名称
DEVICE=网卡名称
ONBOOT=yes
IPADDR=10.0.0.2
NETMASK=255.255.255.0
GATEWAY=10.0.0.254
重启网络管理服务
# systemctl restart NetworkManager
- 第二步:系统dns配置
# cat > /etc/resolv.conf << EOF
nameserver 223.5.5.5
nameserver 114.144.114.114
EOF
验证
# ping www.baidu.com第三步:使用xshell工具远程连接
- 第三步:使用xshell工具远程连接
四、系统-基本配置
1、禁用防火墙与SELinux
关闭firewalld
# systemctl disable firewalld --now
检查确认关闭
# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor
preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
关闭SELinux
# sed -i.bak 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
验证
# grep SELINUX=disabled /etc/selinux/config
SELINUX=disabled
命令行更改
# setenforce 0
验证
# getenforce
Permissive
2、设置主机名
[root@localhost ~]# hostnamectl set-hostname docker-a
[root@localhost ~]# bash
[root@docker-a ~]#
3、系统语言配置
[root@docker-a ~]# localectl set-locale LANG="en_US.UTF-8"
[root@docker-a ~]# echo 'export LANG=en_US.UTF-8' >> /etc/profile
检查确认
[root@docker-a ~]# echo $LANG
en_US.UTF-8
4、本地yum源仓库配置:
[root@docker-a ~]# rm -f /etc/yum.repos.d/*
[root@docker-a ~]# vi /etc/yum.repos.d/local.repo
[root@docker-a ~]# cat /etc/yum.repos.d/local.repo
name=CentOS-$releasever - Base baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&rep o=os
enabled=1 gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
[updates]
name=CentOS-$releasever - Updates baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearc h/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&rep o=updates
enabled=1 gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch
/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&rep o=extras
enabled=1 gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
[centosplus]
name=CentOS-$releasever - Plus baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$base arch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&rep o=centosplus
gpgcheck=1 enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
# 挂载前,先确保CD/DVD是已连接状态(查看下图)
[root@docker-a ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@docker-a ~]# yum clean all && yum makecache
# 失败则:登录红帽认证激活,再一次重试上一步
# subscription-manager register --username=YOUR_USERNAME --password=YOUR_PASSWORD --auto-attach
开机自启
[root@docker-a ~]# echo '/dev/cdrom /mnt iso9660 loop 0 0' >> /etc/fstab
5、安装常用软件:
yum install vim lrzsz tree nc telnet wget lsof chrony bash-completion tcpdump psmisc sysstat net-tools unzip -y
6、配置与阿里时钟服务器同步:
# 加入以下一行代码即可
[root@docker-a ~]# vi /etc/chrony.conf
[root@docker-a ~]# cat /etc/chrony.conf
...
server ntp.aliyun.com iburst
...
# 启动chronyd服务
[root@docker-a ~]# systemctl enable chronyd --now
# 验证
[root@docker-a ~]# chronyc sources
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 203.107.6.88 2 6 37 8 +79us[ -123ms] +/- 33ms
7、额外添加一块数据盘:10G
第一步:VM中虚拟机添加一块10G硬盘
重启虚拟机
# 重启系统
[root@docker-a ~]# reboot
# 查看新添加的硬盘
[root@docker-a ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 39G 0 part
├─rhel-root 253:0 0 37G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
sr0 11:0 1 12.6G 0 rom
第二步:系统里格式化并挂载至/app
[root@docker-a ~]# mkfs.xfs /dev/sdb
[root@docker-a ~]# mkdir /app
[root@docker-a ~]# echo '/dev/sdb /app xfs defaults 0 0' >> /etc/fstab
[root@docker-a ~]# mount -a
[root@docker-a ~]# systemctl daemon-reload
验证:确保已挂载
[root@docker-a ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 848M 0 848M 0% /dev
tmpfs 868M 0 868M 0% /dev/shm
tmpfs 868M 8.7M 859M 1% /run
tmpfs 868M 0 868M 0% /sys/fs/cgroup
/dev/mapper/rhel-root 37G 2.1G 35G 6% /
/dev/sda1 1014M 229M 786M 23% /boot
tmpfs 174M 0 174M 0% /run/user/0
/dev/sdb 10G 104M 9.9G 2% /app
五、安装Docker
阿里镜像站:
https://developer.aliyun.com/mirror/
1、关闭swap
# 命令行关闭
[root@docker-a ~]# swapoff -a
# 关闭开机自启
[root@docker-a ~]# 注释/etc/fstab中的swap行
[root@docker-a ~]# cat /etc/fstab
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=c2d190de-00f5-4c47-bded-7c4e71663caa /boot xfs
defaults 0 0
[root@docker-a ~]# /dev/mapper/rhel-swap none swap defaults 0 0
/dev/sdb /app
2、 安装
# 卸载docker
[root@docker-a ~]# sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 安装必要的一些系统工具
[root@docker-a ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加阿里软件源信息
[root@docker-a ~]# yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@docker-a ~]# sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# 更新并安装Docker-CE
[root@docker-a ~]# sudo yum makecache
[root@docker-a ~]# sudo yum -y install docker-ce
# 开启Docker服务,并设置自启
[root@docker-a ~]# sudo systemctl enable docker --now
3、 Docker验证
[root@docker-a ~]# docker version
Client: Docker Engine - Community
Version: 25.0.3
API version: 1.44
Go version: go1.21.6
Git commit: 4debf41
Built: Tue Feb 6 21:15:16 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 25.0.3
API version: 1.44 (minimum version 1.24)
Go version: go1.21.6
Git commit: f417435
Built: Tue Feb 6 21:14:12 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.28
GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
runc:
Version: 1.1.12
GitCommit: v1.1.12-0-g51d5e94
docker-init:
Version: 0.19.0
GitCommit: de40ad0
4、验证运行helloworld镜像
# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21d
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
5、验证运行一个Ubuntu容器,并打印出当前系统时间
[root@docker-a ~]# docker run -it ubuntu bash
更多推荐
已为社区贡献7条内容
所有评论(0)