[root@2c4g3m ~]# cd /usr/local/src/
[root@2c4g3m src]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
[root@2c4g3m src]# systemctl start docker
[root@2c4g3m src]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
[root@2c4g3m src]# vim /etc/docker/daemon.json
[root@2c4g3m src]# cat /etc/docker/daemon.json
{
"registry-mirrors": [
"https://dockerhub.azk8s.cn",
"https://hub-mirror.c.163.com"
]
}
[root@2c4g3m src]# sudo systemctl daemon-reload
[root@2c4g3m src]# sudo systemctl restart docker
[root@2c4g3m src]# docker info
·········
Registry Mirrors:
https://dockerhub.azk8s.cn/
https://hub-mirror.c.163.com/
Live Restore Enabled: false
[root@2c4g3m src]# docker pull wordpress:latest
[root@2c4g3m src]# docker pull mariadb:10.5
[root@2c4g3m src]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress latest bc5f6567b763 4 days ago 550MB
mariadb 10.5 3a348a04a815 2 weeks ago 407MB
hello-world latest bf756fb1ae65 11 months ago 13.3kB
[root@2c4g3m src]# docker run --name=mariadb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /etc/mariadb/data:/var/lib/mysql -d --restart=always mariadb:10.5
e40517cf51069580e1832781f44484e573d90e005a41a37bda83e99340a1e8f4
[root@2c4g3m src]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e40517cf5106 mariadb:10.5 "docker-entrypoint.s…" 39 seconds ago Up 37 seconds 0.0.0.0:3306->3306/tcp mariadb
367ce2652782 hello-world "/hello" About an hour ago Exited (0) About an hour ago relaxed_rosalind
[root@2c4g3m src]# docker exec -it e40517cf5106 /bin/bash
root@e40517cf5106:/#
root@e40517cf5106:/# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.8-MariaDB-1:10.5.8+maria~focal mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> create database wordpress1;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> create user 'wordpress1'@'%' identified by '1q2w3e';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> grant all privileges on wordpress.* to 'wordpress1'@'%' identified by '1q2w3e';
Query OK, 0 rows affected (0.006 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)
tty1
[root@2c4g3m ~]# docker run --name=wordpress -p 80:80 -v /data/likai/wordpress:/var/www/html -d --restart=always wordpress:latest
4998ece927e9c445959a69e074391eedcc9814a27d49c62dc577e46b44961010
[root@2c4g3m ~]# ss -ntlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:* users:(("sshd",pid=1385,fd=3))
LISTEN 0 128 [::]:3306 [::]:* users:(("docker-proxy",pid=23433,fd=4))
LISTEN 0 128 [::]:80 [::]:* users:(("docker-proxy",pid=24767,fd=4))
[root@2c4g3m ~]#
[root@2c4g3m ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4998ece927e9 wordpress:latest "docker-entrypoint.s…" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp wordpress
e40517cf5106 mariadb:10.5 "docker-entrypoint.s…" 6 hours ago Up 6 hours 0.0.0.0:3306->3306/tcp mariadb
367ce2652782 hello-world "/hello" 7 hours ago Exited (0) 7 hours ago relaxed_rosalind
[root@2c4g3m ~]# docker exec -it 4998ece927e9 /bin/bash
root@4998ece927e9:/var/www/html# cd /var/www/html/
root@4998ece927e9:/var/www/html# vim .htaccess
root@4998ece927e9:/var/www/html# cat .htaccess
# BEGIN WordPress
# 在“BEGIN WordPress”与“END WordPress”之间的指令(行)是
# 动态生成的,只应被WordPress过滤器修改。
# 任何对标记之间的指令的修改都会被覆盖。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
php_value post_max_size 24M
php_value upload_max_filesize 8M
# END WordPress
docker run --name=mariadb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /etc/mariadb/data:/var/lib/mysql -d --restart=always mariadb:latest
docker run --name=wordpress -p 80:80 -v /data/likai/wordpress:/var/www/html -d --restart=always wordpress:latest
create user 'wordpress2'@'%' identified by '1q2w3ee';
MariaDB [(none)]> create user 'wordpress2'@'%' identified by '1q2w3ee';
Query OK, 0 rows affected (0.003 sec)
grant all privileges on wordpress1 to 'wordpress2'@'%' identified by '1q2w3ee';
flush privileges;
MariaDB [(none)]> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
+----------------------------------+
| query |
+----------------------------------+
| User: 'mysqld'@'%'; |
| User: 'root'@'%'; |
| User: 'server'@'%'; |
| User: 'wordpress1'@'%'; |
| User: 'wordpress2'@'%'; |
| User: 'mariadb.sys'@'localhost'; |
| User: 'root'@'localhost'; |
+----------------------------------+
ALTER USER 'root'@'%' IDENTIFIED BY '123456';
[root@VM-0-16-centos wordpress]# pwd
/data/likai/wordpress
[root@VM-0-16-centos wordpress]# vim wp-config.php
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress1' );
/** MySQL database username */
define( 'DB_USER', 'root' );
/** MySQL database password */
define( 'DB_PASSWORD', 'xxxxxx' );
/** MySQL hostname */
define( 'DB_HOST', '172.21.0.16' ); #由于是容器部署,并且腾讯云3306端口没开放,不能用localhost 用eth0的固定IP
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
[root@VM-0-16-centos wordpress]# ip a |grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
inet 172.21.0.16/20 brd 172.21.15.255 scope global eth0