使用Docker安装并设置WordPress(仅用于记录)

[root@20170205test-02 ~]# yum 安装 docker

[root@20170205test-02 ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@20170205test-02 ~]# systemctl start docker
[root@20170205test-02 ~]# systemctl status docker
* docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2017-02-12 14:33:36 JST; 4s ago
     Docs: http://docs.docker.com
 Main PID: 25637 (dockerd-current)
   CGroup: /system.slice/docker.service
           |-25637 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --defau...
           `-25641 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock ...
[root@20170205test-02 ~]# docker pull wordpress
Using default tag: latest
Trying to pull repository docker.io/library/wordpress ... 
latest: Pulling from docker.io/library/wordpress
5040bd298390: Pull complete 
568dce68541a: Pull complete 
6a832068e64c: Pull complete 
3b0f3d176a5b: Pull complete 
20cc248a5690: Pull complete 
6ff565538ee6: Pull complete 
9f1077228581: Pull complete 
57359f144a19: Pull complete 
9754ef36b033: Pull complete 
e156df35b624: Pull complete 
df09daa2224a: Pull complete 
bfa0d8031302: Pull complete 
58ec6fadb2c7: Pull complete 
254919ae58d3: Pull complete 
3fbda78d9add: Pull complete 
1f4006165e89: Pull complete 
1989a57f5f0b: Pull complete 
cd04b95ebe9c: Pull complete 
Digest: sha256:b900bc9ceff22ef1dee076c25a67b6d661f9f108b4347a5646e05a11fef9b866
[root@20170205test-02 ~]# docker pull mysql
Using default tag: latest
Trying to pull repository docker.io/library/mysql ... 
latest: Pulling from docker.io/library/mysql

55370df68315: Pull complete 
fad5195d69cc: Pull complete 
a1034a5fbbfc: Pull complete 
17f3570b42ae: Pull complete 
6bf4b16e5339: Pull complete 
9700c9731729: Pull complete 
f2fea9c5b632: Pull complete 
2f8101f5336d: Pull complete 
0dc8f8a1031a: Pull complete 
a1b9627588c7: Pull complete 
Digest: sha256:5e2ec5964847dd78c83410f228325a462a3bfd796b6133b2bdd590b71721fea6
[root@20170205test-02 ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
docker.io/wordpress   latest              2dc5069d7582        2 days ago          400.1 MB
docker.io/mysql       latest              7666f75adb6b        2 weeks ago         405.6 MB
[root@20170205test-02 ~]# docker run --name mysite_db -e MYSQL_ROOT_PASSWORD=PASSWARD -e MYSQL_DATABASE=mysite -d mysql
8ded182bc75089168ba47a75ae93470cc10de9a9276323050c9a5804b7091146
[root@20170205test-02 ~]# docker run --name mysite --link mysite_db:mysql -p 80:80 -e WORDPRESS_DB_PASSWORD=PASSWARD -d 
wordpress
943a3442862d7009f3fbb67a92ad45554149b80bdee077014d7baf349aebfa68
[root@20170205test-02 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                NAMES
943a3442862d        wordpress           "docker-entrypoint.sh"   6 seconds ago        Up 4 seconds        0.0.0.0:80->80/tcp   mysite
8ded182bc750        mysql               "docker-entrypoint.sh"   About a minute ago   Up About a minute   3306/tcp             mysite_db
[root@20170205test-02 ~]# curl -L "https://github.com/docker/compose/releases/download/1.10.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   600    0   600    0     0    652      0 --:--:-- --:--:-- --:--:--   652
100 7929k  100 7929k    0     0   885k      0  0:00:08  0:00:08 --:--:-- 1625k
[root@20170205test-02 ~]# chown root:root /usr/local/bin/docker-compose
[root@20170205test-02 ~]# chmod +x /usr/local/bin/docker-compose
[root@20170205test-02 ~]# docker-compose -v
docker-compose version 1.10.0, build 4bd6f1a

[root@20170205test-02 ~]# 使用 vim 打开 docker-compose-wordpress.yml 文件

[root@20170205test-02 ~]# cat docker-compose-wordpress.yml 
# docker-compose.yml

version: '2'
services:
  mysite_db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: PASSWARD
  mysite:
    image: wordpress
    environment:
      WORDPRESS_DB_PASSWORD: PASSWARD
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_HOST: mysite_db:3306
      WORDPRESS_DB_NAME: mysite
    ports:
      - "80:80"
    links:
      - mysite_db
[root@20170205test-02 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
943a3442862d        wordpress           "docker-entrypoint.sh"   12 minutes ago      Up 12 minutes       0.0.0.0:80->80/tcp   mysite
8ded182bc750        mysql               "docker-entrypoint.sh"   13 minutes ago      Up 13 minutes       3306/tcp             mysite_db
[root@20170205test-02 ~]# docker stop mysite
mysite
[root@20170205test-02 ~]# docker stop mysite_db
mysite_db
[root@20170205test-02 ~]# ll
total 28
-rw-------. 1 root root 9943 Jan 18 16:13 anaconda-ks.cfg
-rw-r--r--  1 root root  375 Feb 12 14:47 docker-compose-wordpress.yml
-rw-------. 1 root root 9345 Jan 18 16:13 original-ks.cfg
[root@20170205test-02 ~]# docker-compose -f ./docker-compose-wordpress.yml up -d                                   
Creating network "root_default" with the default driver
Creating root_mysite_db_1
Creating root_mysite_1
[root@20170205test-02 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                NAMES
0284370accb8        wordpress           "docker-entrypoint.sh"   12 seconds ago      Up 9 seconds               0.0.0.0:80->80/tcp   root_mysite_1
529571383b2b        mysql               "docker-entrypoint.sh"   13 seconds ago      Up 11 seconds              3306/tcp             root_mysite_db_1
943a3442862d        wordpress           "docker-entrypoint.sh"   17 minutes ago      Exited (0) 3 minutes ago                        mysite
8ded182bc750        mysql               "docker-entrypoint.sh"   18 minutes ago      Exited (0) 3 minutes ago  
[root@20170205test-02 ~]# docker-compose -f ./docker-compose-wordpress.yml up -d
Starting root_mysite_db_1
Starting root_mysite_1
[root@20170205test-02 ~]# docker-compose -f ./docker-compose-wordpress.yml up -d
Starting root_mysite_db_1
Starting root_mysite_1
[root@20170205test-02 ~]# vi docker-compose-wordpress-nginxproxy.yml 
[root@20170205test-02 ~]# cat docker-compose-wordpress.yml 
# docker-compose.yml

version: '2'
services:
  mysite_db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: PASSWARD
  mysite:
    image: wordpress
    environment:
      WORDPRESS_DB_PASSWORD: PASSWARD
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_HOST: mysite_db:3306
      WORDPRESS_DB_NAME: mysite
    ports:
      - "80:80"
    links:
      - mysite_db
[root@20170205test-02 ~]# cat docker-compose-wordpress-nginxproxy.yml 
version: '2'
services:
  proxy:
    image: jwilder/nginx-proxy
    privileged: true
    ports:
      - 80:80
    volumes:
      - /etc/nginx/vhost.d
      - /usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro
  mysite_db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: PASSWARD
  mysite:
    image: wordpress
    environment:
      WORDPRESS_DB_PASSWORD: PASSWARD
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_HOST: mysite_db:3306
      WORDPRESS_DB_NAME: mysite
      VIRTUAL_HOST: xxx。xxx。xxx。xxx
      VIRTUAL_PORT: 80
    links:
      - mysite_db
[root@20170205test-02 ~]# docker-compose -f ./docker-compose-wordpress.yml  stop
Stopping root_mysite_1 ... done
Stopping root_mysite_db_1 ... done
[root@20170205test-02 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
0284370accb8        wordpress           "docker-entrypoint.sh"   9 minutes ago       Exited (0) 16 seconds ago                       root_mysite_1
529571383b2b        mysql               "docker-entrypoint.sh"   9 minutes ago       Exited (0) 14 seconds ago                       root_mysite_db_1
943a3442862d        wordpress           "docker-entrypoint.sh"   26 minutes ago      Exited (0) 13 minutes ago                       mysite
8ded182bc750        mysql               "docker-entrypoint.sh"   27 minutes ago      Exited (0) 13 minutes ago                       mysite_db
[root@20170205test-02 ~]# docker-compose -f ./docker-compose-wordpress-nginxproxy.yml up -d
Pulling proxy (jwilder/nginx-proxy:latest)...
Trying to pull repository docker.io/jwilder/nginx-proxy ... 
latest: Pulling from docker.io/jwilder/nginx-proxy
5040bd298390: Already exists
333547110842: Pull complete
4df1e44d2a7a: Pull complete
f182632afb7c: Pull complete
3d366822d5c2: Pull complete
cbf62fb74e64: Pull complete
d5b019e5c4cf: Pull complete
41102c9c5552: Pull complete
5f6f0965dffc: Pull complete
Digest: sha256:9a2d63aad9068f817c705965f41f2f32fa0bbef6b217ae5c9b2340ef23e3dcba
Starting root_mysite_db_1
Creating root_proxy_1
Recreating root_mysite_1
[root@20170205test-02 ~]# docker ps  -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                      PORTS                         NAMES
7d452bebaa21        wordpress             "docker-entrypoint.sh"   15 seconds ago      Up 13 seconds               80/tcp                        root_mysite_1
22c1c4f4c473        jwilder/nginx-proxy   "/app/docker-entrypoi"   16 seconds ago      Up 13 seconds               0.0.0.0:80->80/tcp, 443/tcp   root_proxy_1
529571383b2b        mysql                 "docker-entrypoint.sh"   12 minutes ago      Up 15 seconds               3306/tcp                      root_mysite_db_1
943a3442862d        wordpress             "docker-entrypoint.sh"   29 minutes ago      Exited (0) 16 minutes ago                                 mysite
8ded182bc750        mysql                 "docker-entrypoint.sh"   30 minutes ago      Exited (0) 16 minutes ago                                 mysite_db
[root@20170205test-02 ~]# docker-compose -f ./docker-compose-wordpress-nginxproxy.yml stop
Stopping root_mysite_1 ... done
Stopping root_proxy_1 ... done
Stopping root_mysite_db_1 ... done
[root@20170205test-02 ~]# docker ps -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                      PORTS               NAMES
7d452bebaa21        wordpress             "docker-entrypoint.sh"   4 minutes ago       Exited (0) 8 seconds ago                        root_mysite_1
22c1c4f4c473        jwilder/nginx-proxy   "/app/docker-entrypoi"   4 minutes ago       Exited (2) 8 seconds ago                        root_proxy_1
529571383b2b        mysql                 "docker-entrypoint.sh"   16 minutes ago      Exited (0) 6 seconds ago                        root_mysite_db_1
943a3442862d        wordpress             "docker-entrypoint.sh"   33 minutes ago      Exited (0) 20 minutes ago                       mysite
8ded182bc750        mysql                 "docker-entrypoint.sh"   34 minutes ago      Exited (0) 20 minutes ago                       mysite_db
广告
将在 10 秒后关闭
bannerAds