1、下载docker的安装文件
https://download.docker.com/linux/static/stable/x86_64/](javascript:void(0))
下载安装文件:docker-18.06.3-ce.tgz
2、 将下载包上传到服务器
通过各种ftp上传工具。如:FinalShell、Xftp等;
3、解压下载包
tar -zxvf docker-18.06.3-ce.tgz
4、将解压出来的docker文件复制到 /usr/bin/ 目录下
cp docker/* /usr/bin/
5、进入/etc/systemd/system/目录,并创建docker.service文件
cd /etc/systemd/system/
Vi docker.service
6、打开docker.service文件,编辑内容(复制粘贴即可):
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
7、授权执行权限
chmod +x /etc/systemd/system/docker.service
8、重载systemd下docker.service文件
systemctl daemon-reload
9、安装完成,启动Docker
# 启动docker
systemctl start docker
10、设置开机启动
systemctl enable docker
11、查看docker状态
systemctl status docker
12、 查看docker版本
docker –v
13、完成大赛试题
(1)在Linux2上安装docker-ce,导入centos镜像。软件包和镜像存放在物理机D:\soft\DockerLinux。
(2)创建名称为skills的容器,映射Linux2的80端口到容器的80端口,在容器内安装apache2,默认网页内容为“HelloContainer”。
[root@bogon opt]# docker load -i CentOS-8-Container-8.3.2011-20201204.2.x86_64.tar.xz
[root@bogon opt]# docker images
[root@bogon opt]# docker run -d --name skills --privileged -p 80:80 centos-8-container-8.3.2011-20201204.2.x86_64 /usr/sbin/init
[root@bogon opt]# docker ps –a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8ea46e12944 centos-8-container-8.3.2011-20201204.2.x86_64 "/bin/bash" About a minute ago Exited (0) 12 seconds ago skills
[root@bogon opt]#docker start skils
[root@bogon opt]# docker exec -it skills /bin/bash
[root@2609c52aa339 /] #vi 修改
进入 cd /etc/yum.repos.d/:
CentOS-Linux-BaseOS.repo
CentOS-Linux-AppStream.repo
CentOS-Linux-Extras.repo
将上面的三个文件中的baseUrl中的mirror.centos.org 替换成 vault.centos.org
[root@2609c52aa339 /] #yum clean
[root@2609c52aa339 /] #yum makecache
[root@2609c52aa339 /]# yum -y install httpd
[root@2609c52aa339 /]#cd /var/www/html
[root@2609c52aa339 /]#echo "this is my web!">index.html
[root@2609c52aa339 /]#systemctl start httpd
[root@2609c52aa339 /]# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 ceb9f843885b
[root@2609c52aa339 /]#curl http://172.17.0.2
this is my web!
[root@2609c52aa339 /]#exit
[root@bogon opt]# docker ps –a
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
250013c8ee7c centos-8-container-8.3.2011-20201204.2.x86_64 "/usr/sbin/init" 7 minutes ago Up 7 minutes 0.0.0.0:8080->80/tcp skills
最后在本地计算机上打开浏览器:http://192.168.4.200:80
显示:this is my web!
14、docker 安装httpd
[root@bogon ~]#docker pull httpd
[root@bogon ~]# docker run -d --name web -p 8080:80 httpd
[root@bogon ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f67fdc71d71 httpd "httpd-foreground" 8 seconds ago Up 4 seconds 0.0.0.0:8080->80/tcp web
本地计算机上打开浏览器:http://192.168.4.200:8080