查看系统版本
[root@dc02 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
查看内核版本
[root@dc02 ~]# uname -r 3.10.0-327.el7.x86_64
关闭selinux和防火墙
setenforce 0 sed -i 's#SELINUX=enforcing#SELINUX=disabled#' /etc/selinux/config systemctl disable firewalld.service systemctl stop firewalld.service
下载docker
[root@dc02 ~]# yum install -y docker
替换国内加速器
[root@dc02 ~]# cat >/etc/docker/daemon.json <<EOF
{ "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"] } EOF [root@dc02 ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"] }
加载生效
[root@dc02 ~]# systemctl daemon-reload
自启动
[root@dc02 ~]# systemctl enable docker [root@dc02 ~]# systemctl start docker
查看状态
[root@dc02 ~]# systemctl status docker
下载官方centos镜像
[root@dc02 ~]# docker pull centos Using default tag: latest Trying to pull repository docker.io/library/centos ... latest: Pulling from docker.io/library/centos 7dc0dca2b151: Pull complete Digest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322 Status: Downloaded newer image for docker.io/centos:latest
查看所有下载镜像
[root@dc02 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/centos latest 49f7960eb7e4 7 weeks ago 200 MB
启动并进入镜像
[root@dc02 ~]# docker run -it --name mynginx centos /bin/bash
安装常用命令
[root@9d76d200aae9 /]# yum install -y wget vim [root@9d76d200aae9 /]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo [root@9d76d200aae9 /]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
安装nginx
[root@9d76d200aae9 /]# yum install -y nginx #docker默认禁止后台运行nginx [root@9d76d200aae9 /]# vim /etc/nginx/nginx.conf #在"user nginx;"下面加上一行"daemon off;"
检查nginx配置文件语法
[root@9d76d200aae9 /]# nginx -t
启动nginx
[root@9d76d200aae9 /]# nginx
启动后命令行是夯筑的,所以打开一个新的SSH连接查看镜像
启动后命令行是夯筑的,所以打开一个新的SSH连接查看镜像
[root@dc02 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9d76d200aae9 centos "/bin/bash" 14 minutes ago Up 14 minutes mynginx
提交镜像并查看
[root@dc02 ~]# docker commit -m "add new docker images" mynginx test/nginx:v1 sha256:5e28845136a33dc8e6175248086a90f9195dda4bdfc014a89b7ee32e37cc24d0 [root@dc02 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test/nginx v1 5e28845136a3 About a minute ago 420 MB docker.io/centos latest 49f7960eb7e4 7 weeks ago 200 MB
测试nginx连通性 [root@dc02 ~]# docker run -p 80:80 --name test_nginx 5e28845136a3 nginx
原文出处转载链接