動機
因為前陣子的網芳勒索病毒
導致公司無法再使用445port了
剛好趁這個機會把開發環境docker化
之前沒做的原因是因為本來是兩個人開發,後來剩我一人以後就懶了。
直接使用網芳連上aws ec2做開發 XD
現在剛好專案到一段落,病毒又來襲,那麼趁這個機會把docker環境建起來吧。
過程
每個docker都要有一個host
由於我是windows派的,悲劇只好起台centos7的虛擬機了。
裝好以後直接安裝docker service
順便記一下,看centos7的ip內建指令是
[root@localhost ~]# ip addr 1: lo:安裝docker servicemtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16777736: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:11:f5:f3 brd ff:ff:ff:ff:ff:ff inet 192.168.80.128/24 brd 192.168.80.255 scope global dynamic eno16777736 valid_lft 1744sec preferred_lft 1744sec inet6 fe80::20c:29ff:fe11:f5f3/64 scope link valid_lft forever preferred_lft forever
[root@localhost ~]# yum install -y docker啟動docker服務
[root@localhost ~]# /bin/systemctl start docker.service [root@localhost ~]# systemctl enable docker.service確認docker版本
[root@localhost ~]# docker -v Docker version 1.12.6, build 1398f24/1.12.6接著依照官方 的介紹抓docker images
[root@localhost ~]# docker pull amazonlinux [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/amazonlinux latest 766ebb052d4f 10 weeks ago 161.8 MB啟動docker container,然後安裝laravel 5.4的必要項目
這邊順便把80 port mapping起來
[root@localhost ~]# docker run -idt -p 80:80 docker.io/amazonlinux 7a208a791d97347cfe1448fe300cb83ddac1f7e4c034c55e3cef5035bd1ee465進去docker看看
[root@localhost ~]# docker attach 7a2 bash-4.2# uname -a Linux 7a208a791d97 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux bash-4.2# cat /etc/issue Amazon Linux AMI release 2017.03 Kernel \r on an \m安裝 laravel要用的全部套件
bash-4.2# yum update -y bash-4.2# yum -y install httpd24 php70 php70w-mysql php70-mysqlnd php70-pdo php70-xml php70-mbstring php70-zip git php70-mcrypt安裝composer,官方網站
bash-4.2# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" bash-4.2# php composer-setup.php All settings correct for using Composer Downloading... Composer (version 1.4.2) successfully installed to: //composer.phar Use it: php composer.phar bash-4.2# mv composer.phar /bin/composer bash-4.2# composer -v Do not run Composer as root/super user! See https://getcomposer.org/root for details ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.4.2 2017-05-17 08:17:52安裝laravel主體
bash-4.2# cd /var/www/html/ bash-4.2# composer global require "laravel/installer"初始化一個專案
bash-4.2# ~/.composer/vendor/laravel/installer/laravel new blog Crafting application... Do not run Composer as root/super user! See https://getcomposer.org/root for details Generating optimized autoload files Do not run Composer as root/super user! See https://getcomposer.org/root for details > php -r "file_exists('.env') || copy('.env.example', '.env');" Do not run Composer as root/super user! See https://getcomposer.org/root for details > Illuminate\Foundation\ComposerScripts::postInstall > php artisan optimize Generating optimized class loader The compiled services file has been removed. Do not run Composer as root/super user! See https://getcomposer.org/root for details > php artisan key:generate Application key [base64:VMbkQ5HXNUI4GDosMmna79gzigWM6RCQjYZXLyjmFWQ=] set successfully. Application ready! Build something amazing.偷懶的把所有都設成777,畢竟只是開發,自己考量
bash-4.2# chown -R nobody:nobody blog bash-4.2# chmod -R 777 blog修改apache設定檔
bash-4.2# vim /etc/httpd/conf/httpd.conf DocumentRoot "/var/www/html/blog/public" # # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory> # Further relax access to the default document root: <Directory "/var/www/html/blog/public"> #重新啟動apache
bash-4.2# service httpd restart
驗證
因為已經把80 port mapping起來了
直接打開瀏覽器打host的ip就好了,成功就會看到laravel的預設首頁了
接著把剛剛的container打成image
先按ctrl+p ctrl+q 跳出來
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7a208a791d97 docker.io/amazonlinux "/bin/bash" 51 minutes ago Up 51 minutes 0.0.0.0:80->80/tcp small_hoover打包成自己的名字
[root@localhost ~]# docker commit -m "new laravel server" -a "weiJ" 7a2 wei:v1 sha256:b61e6d640549b6e2a16d84b2abe3a288b77b83e75181a0ed6561aaaf178bebbf [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE wei v1 b61e6d640549 13 seconds ago 492.2 MB docker.io/amazonlinux latest 766ebb052d4f 10 weeks ago 161.8 MB完成,現在你擁有自己的aws ami linux for laravel 5.4了!!!!
再來看你要不要推上docker hub還是自己私有的docker庫
後記
有人說為什麼我不寫詳細點,很難跟上
拜託我都把我所有打過的指令一字不漏地打出來了
而且每次再寫的時候我都會重新做一次,確保自己不會忘記。
如果你需要更多的laravel或是docker知識,麻煩自己努力找文件
我不是很強,很多東西都是自己努力爬文爬出來的
不懂就問,不會就查,畢竟這邊只是我自己的筆記本,對吧?
最後,大家一起努力,這世界很大很遼闊,知識永遠學不完的!一起加油。
留言
張貼留言