2020-11-15

1夺脾、通過 RPM 安裝 docker 17.03.0 版本并且配置 docker 阿里加速

#安裝必要的一些系統(tǒng)工具
yum install -y yum-utils device-mapper-persistent-data lvm2

#添加軟件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#更新Docker-CE
yum makecache fast

#列出docker版本信息
yum list docker-ce.x86_64 --showduplicates | sort -r

#安裝指定docker版本
yum -y install docker-ce-17.03.0.ce-1.el7.centos docker-ce-cli-17.03.0.ce-1.el7.centos

#配置docker加速
瀏覽器打開http://cr.console.aliyun.com呀潭,注冊(cè)或登錄阿里云賬號(hào)送悔,點(diǎn)擊左側(cè)的鏡像加速器关霸,將會(huì)得到一個(gè)專屬的加速地址

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
}
EOF

systemctl daemon-reload
systemctl restart docker

2、通過 docker 安裝一個(gè) LAPM 架構(gòu)

[root@ubuntu1804 ~]#docker pull centos 
[root@ubuntu1804 ~]#docker run -p 80:80 -itd --name centos centos 
[root@ubuntu1804 ~]#docker exec -it centos bash
[root@d1fb2b5c2187 /]# dnf -y install httpd php  php-mysqlnd   mariadb-server
[root@d1fb2b5c2187 /]# /usr/sbin/httpd
AH00558: httpd: 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
[root@d1fb2b5c2187 /]# ss -ntl
State        Recv-Q       Send-Q              Local Address:Port               Peer Address:Port   
LISTEN       0            128                       0.0.0.0:80                      0.0.0.0:*     

[root@d1fb2b5c2187 /]# /usr/sbin/httpd
AH00558: httpd: 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
[root@d1fb2b5c2187 /]# ss -ntl
State        Recv-Q       Send-Q              Local Address:Port               Peer Address:Port       
[root@d1fb2b5c2187 /]#mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --datadir=/var/lib/mysql/
[root@d1fb2b5c2187 /]#mysqld_safe --defaults-file=/etc/my.cnf > mysqld.log 2>&1 &
[root@d1fb2b5c2187 /]# ss -ntl
State        Recv-Q       Send-Q              Local Address:Port               Peer Address:Port   
LISTEN       0            128                       0.0.0.0:80                      0.0.0.0:*    
LISTEN       0            80    

#修改為prefork模式支持httpd 模塊方式
[root@d1fb2b5c2187 /]# vi /etc/httpd/conf.modules.d/00-mpm.conf 
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so                  
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
#LoadModule mpm_event_module modules/mod_mpm_event.so

[root@d1fb2b5c2187 /]# vi /etc/httpd/conf.d/php.conf
#<IfModule !mod_php5.c>
#  <IfModule !mod_php7.c>
#    # Enable http authorization headers
#    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
#
#    <FilesMatch \.(php|phar)$>
#        SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
#    </FilesMatch>
#  </IfModule>
#</IfModule>

#創(chuàng)建測(cè)試文件
[root@d1fb2b5c2187 /]# cat /var/www/html/lamp.php 
<?php
  phpinfo();
?>

[root@d1fb2b5c2187 /]# kill httpd
[root@d1fb2b5c2187 /]# /usr/sbin/httpd

#測(cè)試訪問http://10.0.0.9/lamp.php

3佳谦、寫出 docker run 命令的延申指令,如怎么在停止一個(gè) docker 容器的時(shí)候自動(dòng)刪除該容器

[root@ubuntu1804 ~]#docker run --help

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

Options:
      --add-host list                  Add a custom host-to-IP mapping (host:ip)
  -a, --attach list                    Attach to STDIN, STDOUT or STDERR
      --blkio-weight uint16            Block IO (relative weight), between 10 and 1000, or 0 to
                                       disable (default 0)
      --blkio-weight-device list       Block IO weight (relative device weight) (default [])
      --cap-add list                   Add Linux capabilities
      --cap-drop list                  Drop Linux capabilities
      --cgroup-parent string           Optional parent cgroup for the container
      --cidfile string                 Write the container ID to the file
      --cpu-period int                 Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int                  Limit CPU CFS (Completely Fair Scheduler) quota
      --cpu-rt-period int              Limit CPU real-time period in microseconds
      --cpu-rt-runtime int             Limit CPU real-time runtime in microseconds
  -c, --cpu-shares int                 CPU shares (relative weight)
      --cpus decimal                   Number of CPUs
      --cpuset-cpus string             CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string             MEMs in which to allow execution (0-3, 0,1)
  -d, --detach                         Run container in background and print container ID
      --detach-keys string             Override the key sequence for detaching a container
      --device list                    Add a host device to the container
      --device-cgroup-rule list        Add a rule to the cgroup allowed devices list
      --device-read-bps list           Limit read rate (bytes per second) from a device (default [])
      --device-read-iops list          Limit read rate (IO per second) from a device (default [])
      --device-write-bps list          Limit write rate (bytes per second) to a device (default [])
      --device-write-iops list         Limit write rate (IO per second) to a device (default [])
      --disable-content-trust          Skip image verification (default true)
      --dns list                       Set custom DNS servers
      --dns-option list                Set DNS options
      --dns-search list                Set custom DNS search domains
      --domainname string              Container NIS domain name
      --entrypoint string              Overwrite the default ENTRYPOINT of the image
  -e, --env list                       Set environment variables
      --env-file list                  Read in a file of environment variables
      --expose list                    Expose a port or a range of ports
      --gpus gpu-request               GPU devices to add to the container ('all' to pass all GPUs)
      --group-add list                 Add additional groups to join
      --health-cmd string              Command to run to check health
      --health-interval duration       Time between running the check (ms|s|m|h) (default 0s)
      --health-retries int             Consecutive failures needed to report unhealthy
      --health-start-period duration   Start period for the container to initialize before
                                       starting health-retries countdown (ms|s|m|h) (default 0s)
      --health-timeout duration        Maximum time to allow one check to run (ms|s|m|h) (default 0s)
      --help                           Print usage
  -h, --hostname string                Container host name
      --init                           Run an init inside the container that forwards signals
                                       and reaps processes
  -i, --interactive                    Keep STDIN open even if not attached
      --ip string                      IPv4 address (e.g., 172.30.100.104)
      --ip6 string                     IPv6 address (e.g., 2001:db8::33)
      --ipc string                     IPC mode to use
      --isolation string               Container isolation technology
      --kernel-memory bytes            Kernel memory limit
  -l, --label list                     Set meta data on a container
      --label-file list                Read in a line delimited file of labels
      --link list                      Add link to another container
      --link-local-ip list             Container IPv4/IPv6 link-local addresses
      --log-driver string              Logging driver for the container
      --log-opt list                   Log driver options
      --mac-address string             Container MAC address (e.g., 92:d0:c6:0a:29:33)
  -m, --memory bytes                   Memory limit
      --memory-reservation bytes       Memory soft limit
      --memory-swap bytes              Swap limit equal to memory plus swap: '-1' to enable
                                       unlimited swap
      --memory-swappiness int          Tune container memory swappiness (0 to 100) (default -1)
      --mount mount                    Attach a filesystem mount to the container
      --name string                    Assign a name to the container
      --network network                Connect a container to a network
      --network-alias list             Add network-scoped alias for the container
      --no-healthcheck                 Disable any container-specified HEALTHCHECK
      --oom-kill-disable               Disable OOM Killer
      --oom-score-adj int              Tune host's OOM preferences (-1000 to 1000)
      --pid string                     PID namespace to use
      --pids-limit int                 Tune container pids limit (set -1 for unlimited)
      --platform string                Set platform if server is multi-platform capable
      --privileged                     Give extended privileges to this container
  -p, --publish list                   Publish a container's port(s) to the host
  -P, --publish-all                    Publish all exposed ports to random ports
      --read-only                      Mount the container's root filesystem as read only
      --restart string                 Restart policy to apply when a container exits (default "no")
      --rm                             Automatically remove the container when it exits
      --runtime string                 Runtime to use for this container
      --security-opt list              Security Options
      --shm-size bytes                 Size of /dev/shm
      --sig-proxy                      Proxy received signals to the process (default true)
      --stop-signal string             Signal to stop a container (default "SIGTERM")
      --stop-timeout int               Timeout (in seconds) to stop a container
      --storage-opt list               Storage driver options for the container
      --sysctl map                     Sysctl options (default map[])
      --tmpfs list                     Mount a tmpfs directory
  -t, --tty                            Allocate a pseudo-TTY
      --ulimit ulimit                  Ulimit options (default [])
  -u, --user string                    Username or UID (format: <name|uid>[:<group|gid>])
      --userns string                  User namespace to use
      --uts string                     UTS namespace to use
  -v, --volume list                    Bind mount a volume
      --volume-driver string           Optional volume driver for the container
      --volumes-from list              Mount volumes from the specified container(s)
  -w, --workdir string                 Working directory inside the container

#停止一個(gè) docker 容器的時(shí)候自動(dòng)刪除該容器
[root@ubuntu1804 ~]#docker run  --rm  alpine cat /etc/issue
Welcome to Alpine Linux 3.11
Kernel \r on an \m (\l)
[root@ubuntu1804 ~]#docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

4滋戳、寫出 docker run 命令在自動(dòng)啟動(dòng) docker 服務(wù)時(shí)通過什么參數(shù)能夠啟動(dòng) docker 中的容器钻蔑,從而實(shí)現(xiàn)容器隨著 docker 服務(wù)的啟動(dòng)而自動(dòng)啟動(dòng)

[root@ubuntu1804 ~]#docker run -d --name nginx --restart=always -p 80:80  nginx
[root@ubuntu1804 ~]#reboot
[root@ubuntu1804 ~]#docker ps 
CONTAINER ID   IMAGE        COMMAND     CREATED        STATUS      PORTS    NAMES
dbdba90076e1 nginx"nginx -g 'daemon of..."  About a minute agoUp 49 seconds0.0.0.0:80->80/tcp   nginx
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市奸鸯,隨后出現(xiàn)的幾起案子咪笑,更是在濱河造成了極大的恐慌,老刑警劉巖娄涩,帶你破解...
    沈念sama閱讀 222,000評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件窗怒,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)兜粘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,745評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門申窘,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人孔轴,你說我怎么就攤上這事剃法。” “怎么了路鹰?”我有些...
    開封第一講書人閱讀 168,561評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵贷洲,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我晋柱,道長(zhǎng)优构,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,782評(píng)論 1 298
  • 正文 為了忘掉前任雁竞,我火速辦了婚禮钦椭,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘碑诉。我一直安慰自己彪腔,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,798評(píng)論 6 397
  • 文/花漫 我一把揭開白布进栽。 她就那樣靜靜地躺著德挣,像睡著了一般。 火紅的嫁衣襯著肌膚如雪快毛。 梳的紋絲不亂的頭發(fā)上格嗅,一...
    開封第一講書人閱讀 52,394評(píng)論 1 310
  • 那天,我揣著相機(jī)與錄音唠帝,去河邊找鬼屯掖。 笑死,一個(gè)胖子當(dāng)著我的面吹牛没隘,可吹牛的內(nèi)容都是我干的懂扼。 我是一名探鬼主播,決...
    沈念sama閱讀 40,952評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼右蒲,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼阀湿!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起瑰妄,我...
    開封第一講書人閱讀 39,852評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤陷嘴,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后间坐,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體灾挨,經(jīng)...
    沈念sama閱讀 46,409評(píng)論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡邑退,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,483評(píng)論 3 341
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了劳澄。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片地技。...
    茶點(diǎn)故事閱讀 40,615評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖秒拔,靈堂內(nèi)的尸體忽然破棺而出莫矗,到底是詐尸還是另有隱情,我是刑警寧澤砂缩,帶...
    沈念sama閱讀 36,303評(píng)論 5 350
  • 正文 年R本政府宣布作谚,位于F島的核電站,受9級(jí)特大地震影響庵芭,放射性物質(zhì)發(fā)生泄漏妹懒。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,979評(píng)論 3 334
  • 文/蒙蒙 一双吆、第九天 我趴在偏房一處隱蔽的房頂上張望眨唬。 院中可真熱鬧,春花似錦伊诵、人聲如沸单绑。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,470評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至歉提,卻和暖如春笛坦,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背苔巨。 一陣腳步聲響...
    開封第一講書人閱讀 33,571評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工版扩, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人侄泽。 一個(gè)月前我還...
    沈念sama閱讀 49,041評(píng)論 3 377
  • 正文 我出身青樓礁芦,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親悼尾。 傳聞我的和親對(duì)象是個(gè)殘疾皇子柿扣,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,630評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容