20191022

docker wordpress

git clone https://github.com/ayubiz/learn_docker_by_examples
若出現沒有git套件請裝:
yum install -y git
cd learn_docker_by_examples/
cd ch09
sudo docker-compose up -d
docker-compose ps
docker ps
docker volume ps
docker volume inspect ch09_db_data
開啟第二台虛擬機,並開啟sshd
systemctl start sshd
回到第一台終端機:
scp -r /var/lib/docker/volumes/ch09_db_data/ user@192.168.56.104:/tmp
再回到第二台檢查是否有拷貝過去
ls /tmp
可以發現有一個檔案名稱叫做ch09_db_data,代表成功將第一台的資料拷貝過去
mv ch09_db_data/ /var/lib/docker/volumes/
yum install git -y
git clone https://github.com/ayubiz/learn_docker_by_examples
docker-compose up -d
確認一下第二台開啟的與第一台能同步。

source by :洪晟峯

Docker 6

Mysql 和wordpress

install docker compose: https://docs.docker.com/compose/install/

Change the user for root curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s-uname -m` -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose

You can use this command to check install or not : [root@localhost ~]# docker-compose --version docker-compose version 1.25.0-rc2, build 661ac20e

For the first , you need to clone git clone http://github.com/ayubiz/learn_docker_by_examples. (sudo yum install -y git) After , enter the directory ` cd ch09 (wordpress) Docker compose configuration is docker-compose.yml

(You need to change the user for root) docker-compose up -d ( d means run in the background) [root@localhost ch09]# docker-compose up -d Creating network "ch09_default" with the default driver Creating volume "ch09_db_data" with default driver Pulling db (mysql:5.7)... 5.7: Pulling from library/mysql 80369df48736: Pull complete

e8f52315cb10: Pull complete

cf2189b391fc: Pull complete

cc98f645c682: Pull complete

27a27ac83f74: Pull complete

fa1f04453414: Pull complete

d45bf7d22d33: Pull complete

c7d49ffebc56: Pull complete

511a8052b204: Pull complete

5d5df4c12444: Pull complete

d482603a2922: Pull complete

Digest:

sha256:44b33224e3c406bf50b5a2ee4286ed0d7f2c5aec1f7fdb70291f7f7c570284dd Status: Downloaded newer image for mysql:5.7 Pulling wordpress (wordpress:latest)... latest: Pulling from library/wordpress

8d691f585fa8: Pull complete

cba12d3fd8b1: Pull complete

cda54d6474c8: Pull complete

412447ed0729: Pull complete

84de6fc539c3: Pull complete

d67567ed6145: Pull complete

22ca6c438da4: Pull complete

a599b0d74880: Pull complete

054fae4e1962: Pull complete

88d0c8554018: Pull complete

d51d0836d94e: Pull complete

7df47d911a02: Pull complete

09c526cad5d1: Pull complete

633437baf2f3: Pull complete

e9c6912f7443: Pull complete

7941d42ed4f6: Pull complete

89698a645fd7: Pull complete

a18c4743d9ab: Pull complete

2639be2121ee: Pull complete

75add61ae005: Pull complete

7b859cb450cb: Pull complete

Digest:

sha256:bc72bd27609e683fb37131191e9ed2c84a2615e98bc9fd3a3b20e8373b25c009 Status: Downloaded newer image for wordpress:latest Creating ch09_db_1 ... done Creating ch09_wordpress_1 ... done

You can use this command to check the process: docker-compose ps [root@localhost ch09]# docker-compose ps

  Name                    Command               State          Ports        

ch09_db_1 docker-entrypoint.sh mysqld Up 3306/tcp, 33060/tcp ch09_wordpress_1 docker-entrypoint.sh apach ... Up 0.0.0.0:8000->80/tcp

查詢database存放的位置到底在哪拉以,未來,就可以針對資料夾備份或是將裡面的資料copy到不同的虛擬機中(虛擬機的配置完全一樣), docker volume ls

[root@localhost ch09]# docker volume ls DRIVER VOLUME NAME local 2cd120a51b5cd8c97dc728bcf14ad0a60247d510f43c3162b10e0a7b7086ec0d local 506b575aec2f1ac7a56e0ab734a536618fa8183c2c7f46f43ee11c939f5a7633 local 832903d677fcf08dc31bceab915f3b4c45e6e918ad2e5718c93f8860aeed305e local 20945729ea55d33b3d68c02bca0cd151e3e3fc471cc0b658993e776d8a125afe local ch09_db_data [root@localhost ch09]# docker volume inspect ch09_db_data [ { "CreatedAt": "2019-10-22T07:05:49-04:00", "Driver": "local", "Labels": { "com.docker.compose.project": "ch09", "com.docker.compose.version": "1.25.0-rc2", "com.docker.compose.volume": "db_data" }, "Mountpoint": "/var/lib/docker/volumes/ch09_db_data/_data", "Name": "ch09_db_data", "Options": null, "Scope": "local" } ]

將第一台裡面的DB資料夾 複製到第二台VM

(VM1)scp -r /var/lib/docker/volumes/ch09_db_data/_data/ user@VM2ip:/tmp (VM2)cd /tmp mv ch09_db_data/_data/ /var/lib/docker/volumes/

(VM2)docker-compose up -d 就可以完整的開啟docker wordpress服務拉~~

If you want to stop and remove the docker-compose’s container , you can use this command: docker-compose down But, docker-compose stop just stop the docker-compose

**docker swarm (非主流) K8s (kubernetes )!!!!!! 很重要

可以用下面這個指令,將wordpress新增多一點 db新增為2台,以面對大量流量的問題。 docker-compose scale wordpress=3 db=2

Wordpress ——— Wordpress ——— db Wordpress ——— db

But, port號 wordpress會都一樣是8000 解決方法是,在yuml配置時,8000這邊可以先拿掉,便可以成功的開啟: [root@localhost ch09]# gedit docker-compose.yml wordpress: depends_on:

  • db

    image: wordpress:latest

    ports:

  • ":80"

    restart: always

    environment:

    WORDPRESS_DB_HOST: db:3306

    WORDPRESS_DB_USER: wordpress

    WORDPRESS_DB_PASSWORD: wordpress

Last updated