Docker containerized applications:
* Deploy the docker environment.
Note: It is
recommended to use Centos7-1810 version. In 1511 version, there will be driver problems and iptables problems
. 1. First configure the yum file of the network: If not, please refer to this document https://blog .csdn.net/smileui/article/details/106738039
yum clean all; yum makecache
2. Install the docker environment:
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io -y
systemctl start docker
systemctl enable docker
3...Configure the domestic warehouse address: realize rapid deployment of mirroring
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://2n9uoybw.mirror.aliyuncs.com"]
}
EOF
4. Restart the service
systemctl daemon-reload && systemctl restart docker
Prepare to deploy the image files needed for
wordpress wordpress is a blog system developed based on PHP+MySQL. If you want to run it, you need to use LAMP or LNMP wordpress:latest. AP or NP
mysql: 5.7 is included by default . Install MySQL database. It is recommended to use version 5.6 or 5.7.
[root@localhost ~]# docker pull wordpress:latest
[root@localhost ~]# docker pull mysql:5.7
1. Prepare the docker-compose tool
to orchestrate the next start of the container (similar to the work plan in daily life)
LAMP start mysql first, then start Apache to
deploy the wordpress application, you should start the mysql container first, then start wordpress
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress latest ee025cbcbc20 3 days ago 539MB
mysql 5.7 1e4405fe1ea9 2 weeks ago 437MB
centos latest 0f3e07c0138f 2 months ago 220MB
2. Prepare epel YUM source
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-
7.repo
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo docker-ce.repo
Prepare pip tool for batch management of toolkits developed in python language (the difference from GitHub binary is mainly in version)
[root@localhost ~]# yum -y install python2-pip
Due to installation dependencies, it is recommended to install all the following packages before installing docker-compose
[root@localhost ~]# yum -y install gcc libffi-devel python-devel openssl-devel openldap-devel
Three, update the pip version
[root@localhost ~]# pip install --upgrade pip
Fourth, switch domestic sources
[root@localhost ~]# pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas
[root@localhost ~]# pip install python-ldap --user -U
[root@localhost ~]# pip install six --user -U
[root@localhost ~]# pip install pyudev --user -U
[root@localhost ~]# pip install dnspython --user -U
[root@localhost ~]# pip install cffi --user -U
Five, install docker-compose
[root@localhost ~]# pip install docker-compose --ignore-installed requests
Six, verify whether the installation is successful
[root@localhost ~]# docker-compose version
docker-compose version 1.25.0, build b42d419
docker-py version: 4.1.0
CPython version: 2.7.5
OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017
Seven, prepare the container image file
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress latest ee025cbcbc20 3 days ago 539MB
mysql 5.7 1e4405fe1ea9 2 weeks ago 437MB
Eight, create a catalog file
[root@localhost ~]# mkdir wordpressproject
[root@localhost ~]# cd wordpressproject/
Nine, write docker-compose.yaml file:
pay attention to the format of the file, pay attention to spaces strictly
[root@localhost wordpressproject]# cat docker-compose.yaml
```powershell
version: '3'
services:
db:
image: mysql:5.7
volumes:
- "./data:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
expose:
- 3306
wordpress:
depends_on:
- db
image: wordpress:latest
links:
- db
ports:
- "8080:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: wordpress
The above code is very important, especially the indentation problem must be handled properly.
Ten, turn on the ip forwarding function (very important)
[root@localhost wordpressproject]# vi /etc/sysctl.conf
[root@localhost wordpressproject]# net.ipv4.ip_forward = 1
[root@localhost wordpressproject]# sysctl -p
11.
Take effect immediately. This part is a help command. Below is the specific startup command docker-compose related commands:
how to use docker-compose
[root@localhost wordpressproject]# docker-compose --help
[root@localhost wordpressproject]# docker-compose up
This command can only be used in the project directory to start the project
[root@localhost wordpressproject]# docker-compose down
Stop and delete the containers that the project has created.
12. Start docker-compse:
[root@localhost wordpressproject]# docker-compose up -d
Creating network "wordpressproject_default" with the default driver
Creating wordpressproject_db_1 ... done
Creating wordpressproject_wordpress_1 ... done
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
4cf5f4cee330 wordpress:latest "docker-entrypoint.s…" About a minute ago Up About a
minute 0.0.0.0:8080->80/tcp wordpressproject_wordpress_1
4d9cb6aee451 mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a
minute 3306/tcp, 33060/tcp wordpressproject_db_1
[root@localhost ~]# ls
anaconda-ks.cfg mysql.tar wordpressproject wordpress.tar
[root@localhost ~]# cd wordpressproject/
[root@localhost wordpressproject]# ls
data docker-compose.yaml
[root@localhost wordpressproject]# ls data
auto.cnf client-key.pem ib_logfile1 private_key.pem sys
ca-key.pem ib_buffer_pool ibtmp1 public_key.pem wordpress
ca.pem ibdata1 mysql server-cert.pem
client-cert.pem ib_logfile0 performance_schema server-key.pem
[root@localhost wordpressproject]# ls data/wordpress/
db.opt
Thirteen, the final test results omit the screenshots of the configuration user name database appearing in the middle