docker를 이용해서 wordpress 테스트 환경을 구축할 수 있다.
wordpress 도커는 mysql을 함께 실행하지 않기 때문에 mysql은 도커 컨테이너를 따로 실행한다.
mysql 5.7 도커 컨테이너를 실행하고 제대로 동작하는지 docker ps로 확인한다.
$ docker run --restart=always --name wordpressdb -e MYSQL_ROOT_PASSWORD=123 -e MYSQL_DATABASE=wordpress -d mysql:5.7
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a54634841ccd mysql:5.7 "docker-entrypoint.sh" 2 minutes ago Up 2 minutes 3306/tcp wordpressdb
wordpress 도커 컨테이너를 실행한다. -p 매개변수는 8080 으로 요청하면 컨테이너에서는 80으로 forwarding 한다.
$ docker run --restart=always -e WORDPRESS_DB_PASSWORD=123 -d --name wordpress --link wordpressdb:mysql -p 8080:80 wordpress
이제 2 개의 도커 컨테이너가 실행 중이다.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76d768dbe13c wordpress "/entrypoint.sh apach" 17 minutes ago Up 17 minutes 0.0.0.0:8080->80/tcp wordpress
a54634841ccd mysql:5.7 "docker-entrypoint.sh" 23 minutes ago Up 23 minutes 3306/tcp wordpressdb
wordpress 도커 컨테이너 설정을 모두 얻는다. 대략적인 정보를 확인할 수 있다.
$ docker inspect wordpress
[
{
"Id": "76d768dbe13cd17c0701c12943170e33de12f9f9853191352f34e7fb5f0b7111",
"Created": "2016-07-24T13:41:50.569702368Z",
"Path": "/entrypoint.sh",
"Args": [
"apache2-foreground"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 2655,
"ExitCode": 0,
"Error": "",
"StartedAt": "2016-07-24T13:41:51.086400125Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:ba0d4f420656196a96f3106b8e22b4e2c00351e48b5218456a8e4833051cc816",
"ResolvConfPath": "/var/lib/docker/containers/76d768dbe13cd17c0701c12943170e33de12f9f9853191352f34e7fb5f0b7111/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/76d768dbe13cd17c0701c12943170e33de12f9f9853191352f34e7fb5f0b7111/hostname",
"HostsPath": "/var/lib/docker/containers/76d768dbe13cd17c0701c12943170e33de12f9f9853191352f34e7fb5f0b7111/hosts",
"LogPath": "/var/lib/docker/containers/76d768dbe13cd17c0701c12943170e33de12f9f9853191352f34e7fb5f0b7111/76d768dbe13cd17c0701c12943170e33de12f9f9853191352f34e7fb5f0b7111-json.log",
"Name": "/wordpress",
"RestartCount": 0,
"Driver": "aufs",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "8080"
}
]
},
"RestartPolicy": {
"Name": "always",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": [
"/wordpressdb:/wordpress/mysql"
],
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Name": "aufs",
"Data": null
},
"Mounts": [
{
"Name": "e0b6d751c7432e4be06a0c0173a70071f0730a42acc3a751a22d45f489011c13",
"Source": "/var/lib/docker/volumes/e0b6d751c7432e4be06a0c0173a70071f0730a42acc3a751a22d45f489011c13/_data",
"Destination": "/var/www/html",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "76d768dbe13c",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"WORDPRESS_DB_PASSWORD=123",
"no_proxy=*.local, 169.254/16",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"PHPIZE_DEPS=autoconf \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c",
"PHP_INI_DIR=/usr/local/etc/php",
"APACHE_CONFDIR=/etc/apache2",
"APACHE_ENVVARS=/etc/apache2/envvars",
"PHP_EXTRA_BUILD_DEPS=apache2-dev",
"PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2",
"GPG_KEYS=0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3",
"PHP_VERSION=5.6.23",
"PHP_FILENAME=php-5.6.23.tar.xz",
"PHP_SHA256=39141e9a617af172aedbbacee7a63eb15502850f7cea20d759a9cffa7cfb0a1a",
"WORDPRESS_VERSION=4.5.3",
"WORDPRESS_SHA1=835b68748dae5a9d31c059313cd0150f03a49269"
],
"Cmd": [
"apache2-foreground"
],
"Image": "wordpress",
"Volumes": {
"/var/www/html": {}
},
"WorkingDir": "/var/www/html",
"Entrypoint": [
"/entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "ef789188d36c51bce68235e3dc7385a7f0b6c1f64579f225927f5b8e5a690a51",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
]
},
"SandboxKey": "/var/run/docker/netns/ef789188d36c",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "c24808d9ef0f20266cd0c16337de7b2d88939853afdc5893a2d1898741f0e292",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:03",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "1a45bc6e96c0909fea2d34bc6b1492adc2839f9d5f893ca013af9300aad4fc33",
"EndpointID": "c24808d9ef0f20266cd0c16337de7b2d88939853afdc5893a2d1898741f0e292",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:03"
}
}
}
}
]
컨테이너 로그를 확인한다.
$ docker logs -f wordpress
WordPress not found in /var/www/html - copying now...
Complete! WordPress has been successfully copied to /var/www/html
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
[Sun Jul 24 13:41:52.317876 2016] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.23 configured -- resuming normal operations
[Sun Jul 24 13:41:52.317926 2016] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
웹 브라우져에서 다음을 실행하면 wordpress 설치화면이 나타난다.
http://localhost:8080 또는
http://localhost:8080/wp-admin/install.php
그리고 $ docker logs -f wordpress 결과에 아파치 로그가 출력된다.
172.17.0.1 - - [24/Jul/2016:14:01:44 +0000] "GET / HTTP/1.1" 302 397 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
172.17.0.1 - - [24/Jul/2016:14:01:44 +0000] "GET /wp-admin/install.php HTTP/1.1" 200 3433 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
....
참고로 docker ps는 현재 실행 중인 도커 컨테이너를 출력하고, docker ps -a는 모든 도커 컨테이너를 출력한다. 상태 정보로 확인할 수 있다.
~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76d768dbe13c wordpress "/entrypoint.sh apach" 21 minutes ago Up 21 minutes 0.0.0.0:8080->80/tcp wordpress
a54634841ccd mysql:5.7 "docker-entrypoint.sh" 27 minutes ago Up 27 minutes 3306/tcp wordpressdb
~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76d768dbe13c wordpress "/entrypoint.sh apach" 21 minutes ago Up 21 minutes 0.0.0.0:8080->80/tcp wordpress
a54634841ccd mysql:5.7 "docker-entrypoint.sh" 27 minutes ago Up 27 minutes 3306/tcp wordpressdb
5f615fc3de99 hello-world "bash" 32 minutes ago Created furious_wozniak
.....
실행 중인 wordpress와 mysql 도커 컨네이너를 모두 stop 시킨다.
$ docker stop 76d768dbe13c
76d768dbe13c
$ docker stop a54634841ccd
a54634841ccd
실행 중인 애플리케이션 목록은 모두 사라진다.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
도커 컨테이너를 실행할 수 있도록 start를 실행한다.
$ docker start a54634841ccd
a54634841ccd
$ docker start 76d768dbe13c
76d768dbe13c
wordpress 도커 컨테이너에 bash 접근을 하려면 docker exec -it 컨테이너ID /bin/bash 또는 docker exec -it 컨테이너ID bash를 실행한다.
$ docker exec -it 76d768dbe13c /bin/bash
root@76d768dbe13c:/var/www/html# hostname
76d768dbe13c
root@76d768dbe13c:/var/www/html# ps -ef | grep apache
root 1 0 24 14:06 ? 00:00:26 apache2 -DFOREGROUND
www-data 54 1 0 14:06 ? 00:00:00 apache2 -DFOREGROUND
www-data 55 1 0 14:06 ? 00:00:00 apache2 -DFOREGROUND
www-data 56 1 0 14:06 ? 00:00:00 apache2 -DFOREGROUND
www-data 57 1 0 14:06 ? 00:00:00 apache2 -DFOREGROUND
www-data 58 1 0 14:06 ? 00:00:00 apache2 -DFOREGROUND
www-data 60 1 0 14:07 ? 00:00:00 apache2 -DFOREGROUND
root 68 61 0 14:08 ? 00:00:00 grep apache
root@76d768dbe13c:/var/www/html# exit
~$
mysql 도커 컨테이너에서도 bash 접근을 할 수 있다.
~$ docker exec -it a54634841ccd /bin/bash
root@a54634841ccd:/# ps -ef | grep mysql
mysql 1 0 0 14:06 ? 00:00:00 mysqld
root 56 50 0 14:17 ? 00:00:00 grep mysql
root@a54634841ccd:/# ls -al
'docker' 카테고리의 다른 글
docker container 실행에 중요한 /data/start.sh (0) | 2016.07.29 |
---|---|
[docker] centos7 이미지에 expressjs를 설치한후 container 실행하기 / docker hub 업로드하기 (0) | 2016.07.26 |
docker 공부 (0) | 2016.07.24 |
[docker] docker 설치 (0) | 2016.07.22 |
[docker] docker 이미지 삭제 (0) | 2016.07.21 |