Docker(二)

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

文章目录

1. 手动制作docker镜像

制作一个基于centos6系统的nginx镜像(单服务)

1 :启动一个纯净的centos:6.9容器,安装nginx
echo '192.168.12.201 mirrors.aliyun.com'
>>/etc/hosts
curl -o /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos-6.repo
curl -o /etc/yum.repos.d/epel.repo
http://mirrors.aliyun.com/repo/epel-6.repo
yum install nginx -y
2 :把安装好服务的容器,提交为镜像
docker container commit eb109f
centos6.9_nginx:v

3 :测试镜像的功能
docker run -d -p 82 :80 centos6.9_nginx:v
nginx -g 'daemon off;'

1. 启动一个基础容器
# 默认初始命令是/bin/bash只要一退出容器容器就会死
docker run -it -p 80:80 centos:7

2. 安装服务
# 安装yum源和epel源
# yum -y install nginx 
systemctl start nginx # 因为容器里面没有D-Bus所以使用不了systemctl
nginx   直接启动
/var/log/nginx/error.log
rm -rf  /usr/share/nginx/html/index.html
echo 'web01' >/usr/share/nginx/html/index.html

ctrl+d 退出容器

3. 将安装好服务的容器提交为镜像
docker container commit 容器id  centos7_nginx:v1
# 基于镜像起容器
docker run -d centos7_nginx:v1  #因为初始命令为/bin/bash所以放后台会直接死
docker run -d -p 80:80 centos7_nginx:v1 nginx -g 'daemon off;'

制作一个基于centos6系统的kod网盘的镜像(多服务)

1 :启动一个centos6.9_nginx:v1,再安装php
echo '192.168.12.201 mirrors.aliyun.com'
>>/etc/hosts
yum install php-fpm php-gd php-mbstring -y
vi /etc/php-fpm.d/www.conf
service php-fpm start
cd /etc/nginx/conf.d/
vi default.conf
mkdir /html
cd /html
wget http://192.168.19.200/191127/kodexplorer4.40.zip 
curl -o kodexplorer4.40.zip http://192.168.19.200/191127/kodexplorer4.40.zip
yum install unzip -y
unzip kodexplorer4.40.zip
chown -R nginx:nginx.

vi /init.sh
#!/bin/bash

service php-fpm start
nginx -g 'daemon off;'

2 :把安装好服务的容器,提交为镜像
docker commit 47208e3e3796 kod:v
3 :测试镜像的功能
docker run -d -p 83 :80 kod:v2 /bin/bash
/init.sh


制作一个基于centos7系统的nginx+sshd双服务镜像

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install nginx -y
yum install openssh-server -y
yum install initscripts -y
/usr/sbin/sshd-keygen
echo '123456'|passwd --stdin root
/usr/sbin/sshd -D
vi /init.sh

2. 自动制作docker镜像

镜像 中药
dockerfile 配方
dockerfile常用指令

FROM 基础镜像
RUN 制作镜像过程中需要的执行命令
CMD 容器启动的时候执行的初始命令容易被替换
ENTRYPOINT 容器启动的时候执行的初始命令不能被替换如果同时使用CMD和ENTRYPOINTcmd命令将作为
ENTRYPOINT命令的参数
ADD 把dockerfile当前目录下的文件拷贝到容器中自动解压tar包
COPY 把dockerfile当前目录下的文件拷贝到容器中不解压tar包
WORKDIR 指定容器的默认工作目录
EXPOSE 镜像要暴露的端口
VOLUME  持久化卷
ENV    环境变量(ssh的密码数据库的密码)
LABEL  镜像的属性标签
MAINTAINER  管理者标识

根据dockerfile自动构建镜像的思路

a:手动制作docker镜像记录历史命令
b根据历史命令编写dockerfile文件
cdocker build构建docker镜像
d测试镜像的功能

3. docker镜像的分层

4. dockerfile的优化

5. 容器间的互联

6. 单机版的容器编排

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: Docker

“Docker(二)” 的相关文章