birk 发表于 2019-2-21 07:38:35

Docker 安装创建

  Docker安装要求
需要64位操作系统
至少要RHEL6.5以上版本
关闭Firewall
  创建Docker的yum源
docker-engine-1.12.1-1.el7.centos.x86_64.rpm
docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm
createrepo .
  vi gzqstca.repo

name=docker
baseurl=ftp://...***
enabled=1
gpgcheck=0
  yum search docker
yum -y install docker-engine
  systemctl enable docker
systemctl start docker
  采用后端存储 cow copy of write
ifconfig 查看
docker images 查看当前机器有的镜像
  Docker hub 镜像仓库
http://hub.docker.com
Docker官方提供公共镜像的仓库(Registry)
  docker search rhel7
docker search centos
docker search nginx
docker search mysql
  docker pull 下载
docker push 上传
  docker search busybox
docker pull busybox
  例:
docdocker help push
  导入镜像
docker load < ***.tar
docker imagers
  导出镜像
docker images
docker save image_name > ***.tar
  docker save busybox(名称):***(唯一的tag name) > busybox.tar
scp busybox.tar docker2:./
docker2 ~]# docker load < busybox.tar
  lftp 192.168.1.254
ls
cd public/
get docker_images.zip
bye
  unzip docker_images.zip
cd docker_images
for i in *
do
docker load < $i
done
  启动镜像
启动centos镜像生成一个容器
docker images
docker run -it centos bash
  开启另一个终端(查看容器信息)
docker ps
  创建启动窗口的命令
docker run -it 镜像的名称:镜像的标签 [启动命令]
latest是默认标签
docker run -it centos:latest cmd
等同docker run -it centos cmd
  查看详细信息
docker inspect 镜像的名称:镜像的标签
  cat >/etc/yum.repos.d/centos.repo/etc/yum.repos.d/centos.repo /var/www/html/index.html
cat /etc/sysconfig/httpd
/usr/sbin/httpd $OPTIONS -DFOREGROUND
  /usr/sbin/httpd -DFOREGROUND
history
exit
  vim Dockerfile
FROM mycentos:latest
RUN yum -y install httpd
ENV EnvironmentFile=/etc/sysconfig/httpd
WORKDIR /var/www/html
RUN echo &quot;Hello world&quot;>index.html
EXPOSE 80
CMD [&quot;/usr/sbin/httpd&quot;, &quot;-DFOREGROUND&quot;]
  docker build -t mycentos:httpd .
docker run -d -p 8888:22 mycentos:httpd
  例:在sshd的镜像上填加httpd
  vim Dockerfiles
FROM mycentos:sshd
RUN yum -y install httpd
ENV EnvironmentFile=/etc/sysconfig/httpd
WORKDIR /var/www/html
RUN echo &quot;Hello world!&quot;>index.html
EXPOSE 22
EXPOSE 80
ADD run.sh /etc/init.d/run.sh
CMD [&quot;/etc/init.d/run.sh&quot;]
  vim run.sh
#!/bin/bash
/usr/sbin/sshd -D &
/usr/sbin/httpd -DFOREGROUND
  chmod +x run.sh
  docker build -t mycentos:sshdhttpd .
  docker run -d -p 8888:80 -p 1022:22 mycentos:sshdhttpd



页: [1]
查看完整版本: Docker 安装创建