Deploy Docker and configure Nginx in CentOS

What is Docker#

View system version

[ root@dc02 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511(Core)

View kernel version

[ root@dc02 ~]# uname -r
3.10.0- 327. el7.x86_64

Turn off selinux and firewall

setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#'/etc/selinux/config
systemctl disable firewalld.service
systemctl stop firewalld.service

Deploy Docker

Download docker

[ root@dc02 ~]# yum install -y docker

Replace domestic accelerator

[ 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"]}

Loading takes effect

[ root@dc02 ~]# systemctl daemon-reload 

Set up auto-start

[ root@dc02 ~]# systemctl enable docker
[ root@dc02 ~]# systemctl start docker

View status

[ root@dc02 ~]# systemctl status docker

Make mirror

Download the official centos mirror

[ root@dc02 ~]# docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ... 
latest: Pulling from docker.io/library/centos
7 dc0dca2b151: Pull complete 
Digest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322
Status: Downloaded newer image for docker.io/centos:latest

View all download mirrors

[ root@dc02 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/centos    latest              49f7960eb7e4        7 weeks ago         200 MB

Boot and enter the mirror

[ root@dc02 ~]# docker run -it --name mynginx centos /bin/bash

Install common commands

[ 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

Install nginx

[ root@9d76d200aae9 /]# yum install -y nginx
# Docker prohibits running nginx in the background by default
[ root@9d76d200aae9 /]# vim /etc/nginx/nginx.conf
# in"user nginx;"Add a line below"daemon off;"

Check nginx configuration file syntax

[ root@9d76d200aae9 /]# nginx -t 

Start nginx

[ root@9d76d200aae9 /]# nginx    
The command line is built after startup, so open a new SSH connection to view the image

The command line is built after startup, so open a new SSH connection to view the mirror

[ root@dc02 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
9 d76d200aae9        centos              "/bin/bash"14 minutes ago      Up 14 minutes                           mynginx

Submit mirror and view

[ 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

Test nginx connectivity

Test nginx connectivity
[ root@dc02 ~]# docker run -p 80:80--name test_nginx 5e28845136a3 nginx

Browser access server IP address

As shown in the figure, the configuration is successful

Recommended Posts

Deploy Docker and configure Nginx in CentOS
Install and configure Docker in Ubuntu
Install and configure FreeIPA in Centos7
Configure centos container to support ssh in Docker
CentOS7 Docker Nginx deployment and operation detailed explanation
Centos6.5 install and configure mongodb
Detailed steps to install and configure k8s cluster in centos 7
Install and configure keepalived under CentOS 5.9
Install MySql with Docker in CentOS7
Deploy and optimize Tomcat under Centos
CentOS 8 - install and configure NFS service
Install and use docker under CentOS 6.8
Install Centos7 operating system in Docker
Configure python3 environment on centos7 and
CentOS Minimal install and configure TIPS
Nginx-ubuntu install Nginx and configure https
Configure Nginx load balancing based on CentOS 7
Configure Nginx forward proxy based on CentOS 7
Installation and deployment of Nginx in Ubuntu
CentOS container installation in Docker uses MySQL
Install CentOS7 virtual machine, configure docker suite
Python and scrapy deployment in centos environment
Deploy python3 and nginx projects on ubuntu18.04
Compile and install nodejs and yum in Centos8
Install Docker CE in yum under CentOS 7
Centos7.6 deploy django+nginx+uwsgi
Install nginx in centos8 custom directory (detailed tutorial)
VMware Fusion install CentOS7 and configure the network
How to install and configure Elasticsearch on CentOS 7
CentOS 7 install Docker
How to install and use Docker on CentOS 7
CentOS 7 deploy OpenLDAP+FreeRadius
CentOS7 install Docker
Deploy Hadoop cluster services in actual CentOS system
How to install and configure VNC on CentOS 8
Configure Nginx to start automatically based on CentOS 7
CentOS7 and Docker configuration Chinese character set problem
Docker installation (CentOS7 installation)
Centos7 installation of PHP and Nginx tutorial detailed
How to install and configure Redis on CentOS 8
Centos7 install Docker
Centos7 install Nginx
Centos7 install docker18
How to install and configure phpMyAdmin on CentOS 6
centos7 install docker
Installation and configuration of CentOS 7 in VMware Workstation
CentOS7 docker installation
How to install and configure Owncloud on CentOS 8
Centos7 configure JDK
CentOS 6 install Docker
Centos8 install Docker
How to install and configure Redmine on CentOS 8
Common issues in IDC computer room and Centos8 installation
Install PHP in yum under CentOS, configure php-fpm service
The difference between CentOS and Ubuntu in Linux system
How to install and configure NFS server on CentOS 8
Kickstart+PXE automatically deploy CentOS6.6
Install centos7 and connect
CentOS MONO nginx running
Install Docker on Centos7
Deploy GitBook under CentOS7