彷佛在菜鳥教程上的Deckfile運用,是不須要這步的。(Deckfile內的FROM指令會自動拉取源鏡像而後展開配置)php
但參考大佬的範例,這步應該爲了得到web存放目錄的相關配置文件,即後面的defualt.conf。html
能夠看到上面有咱們所須要修改的信mysql
彷佛其中的echo指令格式錯了,修改後即成功nginx
在瀏覽器訪問web服務時發生錯誤...很是悲催web
鏡像是存在的,相關容器也有開啓,端口也不存在佔用問題,花了好久都沒發現問題。一直覺得是端口8080:8080的映射問題。sql
後來從新檢查配置文件發現,實際上是路徑寫錯誤了...應該放在講defualt.conf文件放在etc/nginx/conf/裏面docker
修改後成功數據庫
附:Dockerfile和deflaut配置文件瀏覽器
Dockfile:bash
FROM nginx #MAINTAINER IFORMATION MAINTAINER jayer@xiajibaxie.com #WORKDIR WORKDIR /usr/mynginx/ #CONFIGURATION COPY default.conf /etc/nginx/conf.d/ #INDEX RUN echo "This is jayer'nginx images" >> /usr/mynginx/index.html #EXPOSE EXPOSE 8080
defualt.conf:
server { listen 8080; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/mynginx/; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
查看日誌追根溯源發現應該是在schema.sql文件裏面,那裏的表格名字寫錯了
。。。成功後的日誌文件
附:Dockerfile和相關配置文件
Dockerfile:
FROM mysql:5.7 #MAINTAINER INFORMATION MAINTAINER jayer@xiajibaxie.com #EVIRONMENT ENV MYSQL_ALLOW_EMPTY_PASSWORD no ENV MYSQL_ROOT_PASSWORD=123 #CONFIGURATION COPY setup.sh /mysql/setup.sh COPY schema.sql /mysql/schema.sql COPY privileges.sql /mysql/privileges.sql #COMMAND CMD ["sh", "/mysql/setup.sh"]
setup.sh:
#!/bin/bash set -e #查看mysql服務的狀態,方便調試,這條語句能夠刪除 echo `service mysql status` echo '1.啓動mysql....' #啓動mysql service mysql start sleep 3 echo `service mysql status` echo '2.開始導入數據....' #導入數據 mysql < /mysql/schema.sql echo '3.導入數據完畢....' sleep 3 echo `service mysql status` #從新設置mysql密碼 echo '4.開始修改密碼....' mysql < /mysql/privileges.sql echo '5.修改密碼完畢....' #sleep 3 echo `service mysql status` echo `mysql容器啓動完畢,且數據導入成功` tail -f /dev/null ~
privileges.sql:
use mysql; select host, user from user; create user jayer identified by '123456'; grant all on docker_mysql.* to jayer@'%' identified by '123456' with grant option; flush privileges;
schema.sql:
create database `docker_mysql` default character set utf8 collate utf8_general_ci; use docker_mysql; DROP TABLE IF EXISTS Stu; CREATE TABLE Stu ( `Num` varchar(20) NOT NULL, `Name` varchar(20) DEFAULT NULL, `Class` varchar(10) DEFAULT NULL, PRIMARY KEY (`Num`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO Stu (`Num`, `Name`, `Class`) VALUES ('123','jayer','1');