摘要:指定鏡像綁定端口出錯。查看容器顯示,沒有啟動成功。啟動命令網卡信息背景補充構建容器時,使用的端口映射為解決方法改為使用網卡地址,指定端口號。
代碼文件
[root@Optimus /]# cd docker-training/ [root@Optimus docker-training]# ls centos7 mysql php-fpm README.md wordpress [root@Optimus docker-training]# cd wordpress/ [root@Optimus wordpress]# ls Dockerfile init.sh readme.html wp-admin wp-comments-post.php wp-content wp-includes wp-load.php wp-mail.php wp-signup.php xmlrpc.php index.php license.txt wp-activate.php wp-blog-header.php wp-config-sample.php wp-cron.php wp-links-opml.php wp-login.php wp-settings.php wp-trackback.php [root@Optimus wordpress]#
其中,除了dockerfile和init.sh,都是項目代碼文件。推薦把dockerfile放在該目錄下。
查看dockerfile
from csphere/php-fpm:5.4 add init.sh /init.sh entrypoint ["/init.sh", "/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
代碼文件已經了,只需要能解析運行PHP的環境和webserver的鏡像。
在/php-fpm/Dockerfile文件中,最后兩行代碼是onbuild,會在構建WordPress的時候生效。添加所有文件到/app目錄下。
ONBUILD ADD . /app ONBUILD RUN chown -R nginx:nginx /app
文件目錄如下
[root@Optimus wordpress]# ls Dockerfile init.sh readme.html wp-admin wp-comments-post.php wp-content wp-includes wp-load.php wp-mail.php wp-signup.php xmlrpc.php index.php license.txt wp-activate.php wp-blog-header.php wp-config-sample.php wp-cron.php wp-links-opml.php wp-login.php wp-settings.php wp-trackback.php [root@Optimus wordpress]#
其中Dockerfile不必要添加到/app目錄下,只要copy其他的代碼文件即可。
查看當前目錄下所有文件
[root@Optimus wordpress]# ls -a . Dockerfile index.php license.txt wp-activate.php wp-blog-header.php wp-config-sample.php wp-cron.php wp-links-opml.php wp-login.php wp-settings.php wp-trackback.php .. .dockerignore init.sh readme.html wp-admin wp-comments-post.php wp-content wp-includes wp-load.php wp-mail.php wp-signup.php xmlrpc.php [root@Optimus wordpress]#
.dockerignore文件內容
[root@Optimus wordpress]# cat .dockerignore Dockerfile 只有一句dockerfile,代表著除了dockerfile文件,其他文件都會copy到/app目錄下。
WordPress的dockerfile
[root@Optimus wordpress]# cat Dockerfile from csphere/php-fpm:5.4 add init.sh /init.sh entrypoint ["/init.sh", "/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"] [root@Optimus wordpress]#
from執行完畢后,就會執行onbuild去添加代碼文件到/app,然后才會執行add命令。先添加文件,后執行init.sh腳本。
在執行WordPress entrypoint命令時,先執行init.sh腳本,再啟動supervisor。這里啟動supervisor,相當于啟動了Nginx和php-fpm,因為在php-fpm這個鏡像下,supervisor.conf.d目錄下只有Nginx和php-fpm的啟動文件。
entrypoint ["/init.sh", "/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
init.sh腳本
構建WordPress鏡像
dockerfile不在當前目錄下,構建鏡像
[root@Optimus /]# docker build -t csphere/wordpress:4.2 ./docker-training/wordpress/ Sending build context to Docker daemon 19.8 MB Sending build context to Docker daemon Step 0 : FROM csphere/php-fpm:5.4 # Executing 2 build triggers Trigger 0, ADD . /app Step 0 : ADD . /app Trigger 1, RUN chown -R nginx:nginx /app Step 0 : RUN chown -R nginx:nginx /app ---> Running in 5884fc6d3da5 ---> cac915ee5a8f Removing intermediate container dc55f73b6381 Removing intermediate container 5884fc6d3da5 Step 1 : ADD init.sh /init.sh ---> da14e3eab628 Removing intermediate container e03e077ee0ad Step 2 : ENTRYPOINT /init.sh /usr/bin/supervisord -n -c /etc/supervisord.conf ---> Running in 87d28377c3ea ---> 6d90342cc99d Removing intermediate container 87d28377c3ea Successfully built 6d90342cc99d [root@Optimus /]#
查看鏡像
[root@Optimus /]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE csphere/wordpress 4.2 6d90342cc99d About a minute ago 747.3 MB csphere/mysql 5.5 e147ac2a588e 3 days ago 752.7 MB csphere/php-fpm 5.4 1b08c94ce801 5 days ago 709.7 MB csphere/centos 7.1 fd1f7619e63e 6 days ago 613 MB centos centos7.1.1503 879c6d07c60e 6 weeks ago 212.1 MB [root@Optimus /]#
已經有了DB、php-fpm,現在構建一個應用鏡像,并連接DB container。
[root@Optimus /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8e266cd27a63 csphere/mysql:5.5 "/scripts/start" 16 hours ago Up 16 hours 22/tcp, 0.0.0.0:3307->3306/tcp newdb e274049db704 csphere/php-fpm:5.4 "/usr/bin/supervisor 5 days ago Up 5 days 22/tcp, 443/tcp, 0.0.0.0:8080->80/tcp website 2d36dbfc72a0 csphere/centos:7.1 "/usr/bin/supervisor 6 days ago Up 6 days 0.0.0.0:2222->22/tcp base 0d1f6225836b centos "/bin/bash" 7 days ago Exited (127) 7 days ago naughty_engelbart [root@Optimus /]#
查看當前主機的內網網卡的主機地址(服務器的內部IP地址)
[root@Optimus /]# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:1E:67:4E:3D:7B UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Memory:d0960000-d097ffff [root@Optimus /]#
(我的主機在eth0下沒有IP地址,查看其它的網卡eth1)
[root@Optimus /]# ifconfig eth1 eth1 Link encap:Ethernet HWaddr 00:1E:67:4E:3D:7C inet addr:10.10.4.182 Bcast:10.10.4.255 Mask:255.255.255.0 inet6 addr: fe80::21e:67ff:fe4e:3d7c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:224369799 errors:0 dropped:0 overruns:0 frame:0 TX packets:78309983 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:42464926703 (39.5 GiB) TX bytes:107190159141 (99.8 GiB) Memory:d0940000-d095ffff
運行docker WordPress
docker run -d -p 80:80 --name wordpress -e WORDPRESS_DB_HOST=10.10.4.182 -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=csphere2015 csphere/wordpress:4.2 -e 可以傳入環境變量給container。在inut,sh文件中有三個參數需要傳給container。 WORDPRESS_DB_HOST=連哪臺數據庫。 端口映射為3306端口不需要改。 -e可以使用多次。-p可以使用多次。-d不可以使用多次。 WORDPRESS_DB_USER=admin WOREDPRESS_DB_PASSWORD=csphere2015 指定鏡像 csphere/wordpress:4.2
綁定80端口出錯。想重新端口映射,名字沖突。刪除container,重新端口映射,8080和8000均不成功。最后用9090做端口映射。
[root@Optimus /]# docker run -d -p 80:80 --name wordpress -e WORDPRESS_DB_HOST=10.10.4.182 -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=csphere2015 csphere/wordpress:4.2 f0bf3b9ecdf026b06bd79cdcf364354eab8760a7d2ee5fdd5fb715f997a7a649 Error response from daemon: Cannot start container f0bf3b9ecdf026b06bd79cdcf364354eab8760a7d2ee5fdd5fb715f997a7a649: Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use [root@Optimus /]# docker run -d -p 8080:80 --name wordpress -e WORDPRESS_DB_HOST=10.10.4.182 -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=csphere2015 csphere/wordpress:4.2 Error response from daemon: Conflict. The name "wordpress" is already in use by container f0bf3b9ecdf0. You have to delete (or rename) that container to be able to reuse that name. [root@Optimus /]# docker rm wordpress wordpress [root@Optimus /]# docker run -d -p 8080:80 --name wordpress -e WORDPRESS_DB_HOST=10.10.4.182 -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=csphere2015 csphere/wordpress:4.2 2a9942d2ce32aa673d14563378d18b53970ede65b6599cb9880fe6d86010cc77 Error response from daemon: Cannot start container 2a9942d2ce32aa673d14563378d18b53970ede65b6599cb9880fe6d86010cc77: Bind for 0.0.0.0:8080 failed: port is already allocated [root@Optimus /]# docker rm wordpress wordpress [root@Optimus /]# docker run -d -p 8000:80 --name wordpress -e WORDPRESS_DB_HOST=10.10.4.182 -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=csphere2015 csphere/wordpress:4.2 85c51e130edc625c9c77040a8ba0c1f4dfcdbf419daec74f97cb3d9a385202f7 Error response from daemon: Cannot start container 85c51e130edc625c9c77040a8ba0c1f4dfcdbf419daec74f97cb3d9a385202f7: Error starting userland proxy: listen tcp 0.0.0.0:8000: bind: address already in use [root@Optimus /]# docker rm wordpress wordpress [root@Optimus /]# docker run -d -p 9090:80 --name wordpress -e WORDPRESS_DB_HOST=10.10.4.182 -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=csphere2015 csphere/wordpress:4.2 18e21a1d127f1f99f12d67a67ee8a26391f992d7e93fbd2c78d45235c475e74a [root@Optimus /]#
查看容器
[root@Optimus /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 18e21a1d127f csphere/wordpress:4.2 "/init.sh /usr/bin/s 5 minutes ago Exited (1) 4 minutes ago wordpress 8e266cd27a63 csphere/mysql:5.5 "/scripts/start" 23 hours ago Up 23 hours 22/tcp, 0.0.0.0:3307->3306/tcp newdb e274049db704 csphere/php-fpm:5.4 "/usr/bin/supervisor 6 days ago Up 6 days 22/tcp, 443/tcp, 0.0.0.0:8080->80/tcp website 2d36dbfc72a0 csphere/centos:7.1 "/usr/bin/supervisor 7 days ago Up 7 days 0.0.0.0:2222->22/tcp base 0d1f6225836b centos "/bin/bash" 8 days ago Exited (127) 8 days ago naughty_engelbart
顯示exited,沒有啟動成功。刪除WordPress,重啟,查看容器,啟動成功。
[root@Optimus /]# docker rm wordpress wordpress [root@Optimus /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8e266cd27a63 csphere/mysql:5.5 "/scripts/start" 23 hours ago Up 23 hours 22/tcp, 0.0.0.0:3307->3306/tcp newdb e274049db704 csphere/php-fpm:5.4 "/usr/bin/supervisor 6 days ago Up 6 days 22/tcp, 443/tcp, 0.0.0.0:8080->80/tcp website 2d36dbfc72a0 csphere/centos:7.1 "/usr/bin/supervisor 7 days ago Up 7 days 0.0.0.0:2222->22/tcp base 0d1f6225836b centos "/bin/bash" 8 days ago Exited (127) 8 days ago naughty_engelbart [root@Optimus /]# docker run -d -p 9090:80 --name wordpress -e WORDPRESS_DB_HOST=10.10.4.182 -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=csphere2015 csphere/wordpress:4.2 fcf40517154261e3b7768272d1c856df63f5703455ccd229d22ba57ab9656163 [root@Optimus /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fcf405171542 csphere/wordpress:4.2 "/init.sh /usr/bin/s 3 seconds ago Up 2 seconds 22/tcp, 443/tcp, 0.0.0.0:9090->80/tcp wordpress 8e266cd27a63 csphere/mysql:5.5 "/scripts/start" 23 hours ago Up 23 hours 22/tcp, 0.0.0.0:3307->3306/tcp newdb e274049db704 csphere/php-fpm:5.4 "/usr/bin/supervisor 6 days ago Up 6 days 22/tcp, 443/tcp, 0.0.0.0:8080->80/tcp website 2d36dbfc72a0 csphere/centos:7.1 "/usr/bin/supervisor 7 days ago Up 7 days 0.0.0.0:2222->22/tcp base 0d1f6225836b centos "/bin/bash" 8 days ago Exited (127) 8 days ago naughty_engelbart [root@Optimus /]#
使用80端口做映射,訪問的時候可以不用加端口號訪問。否則要加上端口號。
出錯:成功啟動過了幾分鐘,發現,又excited了。。
[root@Optimus /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fcf405171542 csphere/wordpress:4.2 "/init.sh /usr/bin/s 2 minutes ago Exited (1) 2 minutes ago wordpress 8e266cd27a63 csphere/mysql:5.5 "/scripts/start" 23 hours ago Up 23 hours 22/tcp, 0.0.0.0:3307->3306/tcp newdb e274049db704 csphere/php-fpm:5.4 "/usr/bin/supervisor 6 days ago Up 6 days 22/tcp, 443/tcp, 0.0.0.0:8080->80/tcp website 2d36dbfc72a0 csphere/centos:7.1 "/usr/bin/supervisor 7 days ago Up 7 days 0.0.0.0:2222->22/tcp base 0d1f6225836b centos "/bin/bash" 8 days ago Exited (127) 8 days ago naughty_engelbart [root@Optimus /]#
訪問失敗
查看出錯日志
[root@Optimus wordpress]# docker logs -f wordpress PHP Notice: Undefined offset: 1 in - on line 4 PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.22" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.22" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.22" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.22" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.22" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.22" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.22" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.22" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.22" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.22" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.22" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.22" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.22" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.22" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.22" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.22" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.22" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.22" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.22" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.22" (using password: YES) [root@Optimus wordpress]#
有人建議我,臨時進入docker連接數據庫,運行如下:
root@Optimus ~]# docker run -it wordpress bash Unable to find image "wordpress:latest" locally latest: Pulling from wordpress 632d62e9ff45: Pulling fs layer 2309d29c605a: Pull complete b5c24cf2be08: Pull complete 4b0489c8c5ad: Pull complete 0e18f8fbae80: Pull complete ae8ee28d33fd: Pull complete 4e6bd1f11ffa: Pull complete b150aee2f63a: Pull complete bda04964adbb: Pull complete 765636a32409: Pull complete 9f39310817a4: Pull complete d5965880f205: Pull complete bc291240dd82: Pull complete ed3c4a2166ea: Pull complete 7f9f8040b904: Pull complete 30d2ca86be32: Pull complete 9796545de9ab: Pull complete 96f8917e11d8: Pull complete b3aebdc4c86d: Pull complete dfc5c74517f4: Pull complete b74ab8ff8171: Pull complete f8f5b923aa4a: Pull complete d336bb27db75: Pull complete 76d91343f4f9: Pull complete 640a07199820: Pull complete 5fb5a73259de: Pull complete 1ff113204b89: Pull complete f0d30083f45e: Pull complete 95cf8f007a47: Pull complete e54ef1de6066: Pull complete 4c985e73a00d: Pull complete 2b1f410ae0f1: Pull complete f6e007144096: Pull complete 86b573b7bc9b: Pull complete a1c0c746f816: Pull complete df87483bb3b4: Pull complete 906569adf667: Pull complete 5bdd010bcd76: Pull complete c9986e430552: Pull complete b027afd30886: Pull complete Digest: sha256:b277723a281b94d5d28058b346361704f84caa681ff45ccf89f68bf3ba96e788 Status: Downloaded newer image for wordpress:latest root@de644e92ee52:/var/www/html#
shell命令沒有指定鏡像,系統找不到最新版本的WordPress鏡像,pull了一個新的WordPress鏡像,構建了容器,然后進入了這個容器。好像不對。
刪除這個容器:
[root@Optimus ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES de644e92ee52 wordpress "docker-entrypoint.s 8 minutes ago Exited (0) 37 seconds ago mad_hodgkin 8e266cd27a63 csphere/mysql:5.5 "/scripts/start" 45 hours ago Up 45 hours 22/tcp, 0.0.0.0:3307->3306/tcp newdb e274049db704 csphere/php-fpm:5.4 "/usr/bin/supervisor 7 days ago Up 7 days 22/tcp, 443/tcp, 0.0.0.0:8080->80/tcp website 2d36dbfc72a0 csphere/centos:7.1 "/usr/bin/supervisor 8 days ago Up 8 days 0.0.0.0:2222->22/tcp base 0d1f6225836b centos "/bin/bash" 9 days ago Exited (127) 9 days ago naughty_engelbart [root@Optimus ~]# docker rm mad_hodgkin mad_hodgkin [root@Optimus ~]#
查看數據庫用戶
MariaDB [(none)]> select * from mysql.user;
Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
localhost | root | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | 0 | 0 | 0 | 0 | |||||||
9ad32fb968fe | root | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | 0 | 0 | 0 | 0 | |||||||
127.0.0.1 | root | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | 0 | 0 | 0 | 0 | |||||||
::1 | root | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | 0 | 0 | 0 | 0 | |||||||
localhost | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | 0 | 0 | 0 | 0 | ||||||||
9ad32fb968fe | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | 0 | 0 | 0 | 0 | ||||||||
% | admin | *318BF8C339F1F04B052E3D1ED22C2B5873740C5A | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | 0 | 0 | 0 | 0 | ||||||
localhost | admin | *318BF8C339F1F04B052E3D1ED22C2B5873740C5A | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | 0 | 0 | 0 | 0 | ||||||
127.0.0.1 | admin | *318BF8C339F1F04B052E3D1ED22C2B5873740C5A | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | 0 | 0 | 0 | 0 |
網卡信息
[root@Optimus centos7]# ifconfig docker0 Link encap:Ethernet HWaddr 02:C4:0F:42:9D:A4 inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::ac31:7eff:fe21:61bb/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:98676 errors:0 dropped:0 overruns:0 frame:0 TX packets:148581 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:4576610 (4.3 MiB) TX bytes:222704957 (212.3 MiB)
使用IP地址172.17.42.1構建容器
[root@Optimus /]# docker run -d -p 9090:80 --name wordpress -e WORDPRESS_DB_HOST=172.17.42.1 -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=csphere2015 csphere/wordpress:4.2 6a1942015dd23bbf6252f1a4836ada09ffb40a6e8f815480b22e31ab1f2847ed [root@Optimus /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a1942015dd2 csphere/wordpress:4.2 "/init.sh /usr/bin/s 6 seconds ago Up 3 seconds 22/tcp, 443/tcp, 0.0.0.0:9090->80/tcp wordpress 8e266cd27a63 csphere/mysql:5.5 "/scripts/start" 47 hours ago Up 47 hours 22/tcp, 0.0.0.0:3307->3306/tcp newdb e274049db704 csphere/php-fpm:5.4 "/usr/bin/supervisor 7 days ago Up 7 days 22/tcp, 443/tcp, 0.0.0.0:8080->80/tcp website 2d36dbfc72a0 csphere/centos:7.1 "/usr/bin/supervisor 8 days ago Up 8 days 0.0.0.0:2222->22/tcp base 0d1f6225836b centos "/bin/bash" 9 days ago Exited (127) 9 days ago naughty_engelbart [root@Optimus /]#
訪問172.17.42.1:9090失敗。
再次查看容器
[root@Optimus /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a1942015dd2 csphere/wordpress:4.2 "/init.sh /usr/bin/s 2 minutes ago Exited (1) About a minute ago wordpress 8e266cd27a63 csphere/mysql:5.5 "/scripts/start" 47 hours ago Up 47 hours 22/tcp, 0.0.0.0:3307->3306/tcp newdb e274049db704 csphere/php-fpm:5.4 "/usr/bin/supervisor 7 days ago Up 7 days 22/tcp, 443/tcp, 0.0.0.0:8080->80/tcp website 2d36dbfc72a0 csphere/centos:7.1 "/usr/bin/supervisor 8 days ago Up 8 days 0.0.0.0:2222->22/tcp base 0d1f6225836b centos "/bin/bash" 9 days ago Exited (127) 9 days ago naughty_engelbart [root@Optimus /]#
查看日志
[root@Optimus /]# docker logs -f wordpress PHP Notice: Undefined offset: 1 in - on line 4 PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.28" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.28" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.28" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.28" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.28" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.28" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.28" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.28" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.28" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.28" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.28" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.28" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.28" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.28" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.28" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.28" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.28" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.28" (using password: YES) PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user "admin"@"172.17.0.28" (using password: YES) in - on line 7 MySQL Connection Error: (1045) Access denied for user "admin"@"172.17.0.28" (using password: YES) [root@Optimus /]#問題描述
通過docker run啟動一個 WordPress 應用的 docker 容器時,顯示啟動成功為UP狀態,但無法訪問
WordPress 應用,并且幾分鐘后 container 的狀態變為excited。
啟動命令
docker run -d -p 9090:80 --name wordpress -e WORDPRESS_DB_HOST=10.10.4.182 -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=csphere2015 csphere/wordpress:4.2
網卡信息
[root@Optimus /]# ifconfig docker0 Link encap:Ethernet HWaddr 02:C4:0F:42:9D:A4 inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::ac31:7eff:fe21:61bb/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:99200 errors:0 dropped:0 overruns:0 frame:0 TX packets:149257 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:5452754 (5.2 MiB) TX bytes:222793983 (212.4 MiB) eth0 Link encap:Ethernet HWaddr 00:1E:67:4E:3D:7B UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Memory:d0960000-d097ffff eth1 Link encap:Ethernet HWaddr 00:1E:67:4E:3D:7C inet addr:10.10.4.182 Bcast:10.10.4.255 Mask:255.255.255.0 inet6 addr: fe80::21e:67ff:fe4e:3d7c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:225323670 errors:0 dropped:0 overruns:0 frame:0 TX packets:78415571 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:42781224797 (39.8 GiB) TX bytes:107201976978 (99.8 GiB) Memory:d0940000-d095ffff
背景補充
構建DB容器時,使用的端口映射為3307:3306.解決方法
改為使用docker0網卡地址172.17.42.1,指定3307端口號。網頁訪問地址為eth1:9090,也就是10.10.4.182:9090.訪問成功!
[root@Optimus /]# docker run -d -p 9090:80 --name wordpress -e WORDPRESS_DB_HOST=172.17.42.1:3307 -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=csphere2015 csphere/wordpress:4.2 6472364a37f5db3cee78608a649b0a9772952343914212fa8125faa0bcdc4152
成功。
配置WordPress時,如果沒有配置數據庫以及數據庫用戶和密碼時,在第一頁需要填寫連接哪個數據庫、數據庫服務器是哪臺IP地址或者域名。這里已經設置好了,所以不需要再填寫。
選擇簡體中文,點擊繼續.
用戶名:admin
密碼:admin
安裝完成
登錄
登錄成功
訪問WordPress主頁
基礎環境鏡像+中間件鏡像+WordPress的應用鏡像
其中WordPress可以是自己的應用程序。
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/26020.html
摘要:指定鏡像綁定端口出錯。查看容器顯示,沒有啟動成功。啟動命令網卡信息背景補充構建容器時,使用的端口映射為解決方法改為使用網卡地址,指定端口號。 代碼文件 [root@Optimus /]# cd docker-training/ [root@Optimus docker-training]# ls centos7 mysql php-fpm README.md wordpress...
摘要:構建鏡像時,首先要有一個基礎鏡像,然后有中間件鏡像,最后生成一個應用鏡像?,F在作為基礎鏡像,下面來構建兩個中間件鏡像鏡像具有和能力的鏡像。同時,用文件覆蓋默認的配置文件。構建鏡像查看鏡像以上鏡像已經做好了。 以上已經構建好了一個基礎的docker鏡像centos7。 構建docker鏡像時,首先 要有一個基礎鏡像,然后有中間件鏡像,最后生成一個應用鏡像。 現在centos7作為基礎鏡...
摘要:構建鏡像時,首先要有一個基礎鏡像,然后有中間件鏡像,最后生成一個應用鏡像?,F在作為基礎鏡像,下面來構建兩個中間件鏡像鏡像具有和能力的鏡像。同時,用文件覆蓋默認的配置文件。構建鏡像查看鏡像以上鏡像已經做好了。 以上已經構建好了一個基礎的docker鏡像centos7。 構建docker鏡像時,首先 要有一個基礎鏡像,然后有中間件鏡像,最后生成一個應用鏡像。 現在centos7作為基礎鏡...
摘要:如果有服務器需要維護重啟時,也會重啟,此時端口會發生變化,仍然會隨機拿一個沒有使用的端口號來和號端口做端口映射。除非該刪掉后,端口號會被分配給其他使用。 Dockerfile Docker是軟件工業上的集裝箱技術。 通過以下文件制作Docker鏡像 [root@Optimus docker-training]# cd centos7/ [root@Optimus centos7]# l...
閱讀 3172·2021-09-22 15:05
閱讀 2748·2019-08-30 15:56
閱讀 1054·2019-08-29 17:09
閱讀 792·2019-08-29 15:12
閱讀 2076·2019-08-26 11:55
閱讀 3037·2019-08-26 11:52
閱讀 3370·2019-08-26 10:29
閱讀 1374·2019-08-23 17:19