本文共 2306 字,大约阅读时间需要 7 分钟。
查看系统版本
[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/configsystemctl disable firewalld.servicesystemctl stop firewalld.service下载docker
[root@dc02 ~]# yum install -y docker
替换国内加速器
[root@dc02 ~]# cat >/etc/docker/daemon.json <<EOF
{
"registry-mirrors": [""] }EOF[root@dc02 ~]# cat /etc/docker/daemon.json { "registry-mirrors": [""] }
加载生效
[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: latestTrying to pull repository docker.io/library/centos ... latest: Pulling from docker.io/library/centos7dc0dca2b151: Pull complete Digest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322Status: Downloaded newer image for docker.io/centos:latest查看所有下载镜像
[root@dc02 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZEdocker.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 [root@9d76d200aae9 /]# wget -O /etc/yum.repos.d/epel.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 NAMES9d76d200aae9 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 imagesREPOSITORY TAG IMAGE ID CREATED SIZEtest/nginx v1 5e28845136a3 About a minute ago 420 MBdocker.io/centos latest 49f7960eb7e4 7 weeks ago 200 MB测试nginx连通性
[root@dc02 ~]# docker run -p 80:80 --name test_nginx 5e28845136a3 nginx原文出处
转载于:https://blog.51cto.com/14210437/2354649