Docker Cookbook


Using Docker Compose to Create a WordPress Site



Download 6,31 Mb.
Pdf ko'rish
bet157/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   153   154   155   156   157   158   159   160   ...   260
Bog'liq
Docker Cookbook

7.1 Using Docker Compose to Create a WordPress Site
Problem
You have created a WordPress site using 
Recipe 1.16
, but you would like to describe
the multicontainer setup in a clear manifest and bring up the containers in a single
command.
Solution
Use Docker 
Compose
, a command-line utility to define and run multicontainer
applications with Docker. With Compose, you define the services that need to run in
a YAML file. Then bring up the services by using the 
docker-compose
command.
The first thing to do is to 
install
 Compose. You can install it via the Python index or
via a single 
curl
command.
If you are starting on your own Docker host, install Compose manually via the
Python package index using 
pip
:
$ sudo apt-get install python-pip
$ sudo pip install -U docker-compose
Or via 
curl
:
194 | Chapter 7: The Docker Ecosystem: Tools


$ curl -L https://github.com/docker/compose/releases/download/1.4.0/\
docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
If you are using my examples, you are just a 
vagrant up
away from using Compose:
$ git clone https://github.com/how2dock/docbook.git
$ cd docbook/ch07/compose/
$ vagrant up
$ vagrant ssh
$ docker-compose --version
docker-compose 1.4.0
The next step is to define the two containers that compose your WordPress installa‐
tion in a YAML file. Each service will run via a container. You give them a name. In
this case, you will call the WordPress service 
wordpress
and the MySQL service 
db
.
Each service will then be defined by an image. The various arguments given at the
command line in 
Recipe 1.16
 need to be set in this YAML config file: the exposed
ports, the environment variables, and the mounted volumes.
Create the following 
docker-compose.yml
text file (if you are using my Vagrant
machine, the file is already in 
/vagrant/docker-compose.yml
):
wordpress:
image: wordpress
links:
- mysql
ports:

"80:80"
environment:
- WORDPRESS_DB_NAME=wordpress
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpresspwd
mysql:
image: mysql
volumes:
- /home/docker/mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=wordpressdocker
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=wordpresspwd
To bring up the two containers, type 
docker-compose up -d
at the command line, in
the directory where you have your 
docker-compose.yml
file. The two linked containers
will start, and you will be able to access the WordPress site by opening your browser
at 
http://
:
$ docker-compose up -d
Creating vagrant_mysql_1...
Creating vagrant_wordpress_1...
$ docker-compose ps
Name Command State Ports

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   153   154   155   156   157   158   159   160   ...   260




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish