7.1 django項(xiàng)目-新聞博客系統(tǒng)之新聞搜索1

Docker

一、docker安裝

1、docker官方安裝

ubuntu下安裝

lsb_release -a   # 查看系統(tǒng)信息
uname -a        # 查看位數(shù)

如果是第一次安裝,你需要先添加docker的源然后再安裝

1、更新包

$ sudo apt-get update

2、安裝證書(shū)

$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

3、添加docker的官方GPGkey

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

4、添加docker源

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

5、再次跟新包索引

$ sudo apt-get update

6、安裝docker

$ sudo apt-get install docker-ce

7、檢測(cè)

檢測(cè)安裝是否成功

$ sudo docker run hello-world

安裝成功會(huì)出現(xiàn)如下輸出:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

安裝后可能出現(xiàn)問(wèn)題

安裝docker之后,測(cè)試hello-world鏡像,終端卡在Unable to find image 'hello-world:latest' locally位置

參考:https://blog.csdn.net/wireless911/article/details/88989620

2、國(guó)內(nèi)源安裝docker

參考:http://www.lxweimin.com/p/9b1dd79b5708?tdsourcetag=s_pcqq_aiomsg

為了方便使用,不用sudo就可以運(yùn)行docker命令,安裝好docker后再命令行輸入如下命令:

  $ sudo usermod -aG docker $USER

運(yùn)行正常后,重新連接即可。

二、docker簡(jiǎn)單使用

1、docker基本使用

啟動(dòng)docker 查看docker版本號(hào)

$ systemctl start docker

設(shè)置開(kāi)機(jī)啟動(dòng)docker

$ systemctl enable docker

停止docker

$ systemctl stop docker

查看幫助

$ docker --help
[root@localhost ~]# docker --help

Usage:  docker COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/root/.docker")
  -D, --debug              Enable debug mode
      --help               Print usage
  -H, --host list          Daemon socket(s) to connect to (default [])
  -l, --log-level string   Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  container   Manage containers
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  volume      Manage volumes

Commands:
  attach      Attach to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

2、Docker鏡像操作

操作 命令 說(shuō)明
檢索 docker search 關(guān)鍵字egdocker search mysql 我們經(jīng)常去docker hub上檢索鏡像的詳細(xì)信息,如鏡像的TAG
拉取 docker pull 鏡像名:tag :tag是可選的,tag表示標(biāo)簽,多為軟件的版本,默認(rèn)是latest(最新的)
列表 docker images 查看所有本地鏡像
刪除 docker rmi image-id 刪除指定的本地鏡像

1、檢索鏡像

[root@localhost ~]# docker search centos

默認(rèn)會(huì)去 https://hub.docker.com/ 搜索,搜過(guò)結(jié)果如下

[root@localhost ~]# docker search centos
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
centos                             The official build of CentOS.                   4709                [OK]                
ansible/centos7-ansible            Ansible on Centos7                              118                                     [OK]
jdeathe/centos-ssh                 CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x86…   99                                      [OK]
consol/centos-xfce-vnc             Centos container with "headless" VNC session…   63                                      [OK]
imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              45                                      [OK]
tutum/centos                       Simple CentOS docker image with SSH access      43                                      
centos/mysql-57-centos7            MySQL 5.7 SQL database server                   39                                      
gluster/gluster-centos             Official GlusterFS Image [ CentOS-7 +  Glust…   34                                      [OK]
openshift/base-centos7             A Centos7 derived base image for Source-To-I…   33                                      
centos/python-35-centos7           Platform for building and running Python 3.5…   30                                      
centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relational …   29                                      
kinogmt/centos-ssh                 CentOS with SSH                                 22                                      [OK]
openshift/jenkins-2-centos7        A Centos7 based Jenkins v2.x image for use w…   15                                      
pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag names…   7                                       
openshift/wildfly-101-centos7      A Centos7 based WildFly v10.1 image for use …   5                                       
openshift/jenkins-1-centos7        DEPRECATED: A Centos7 based Jenkins v1.x ima…   4                                       
darksheer/centos                   Base Centos Image -- Updated hourly             3                                       [OK]
pivotaldata/centos-mingw           Using the mingw toolchain to cross-compile t…   2                                       
pivotaldata/centos                 Base centos, freshened up a little with a Do…   2                                       
blacklabelops/centos               CentOS Base Image! Built and Updates Daily!     1                                       [OK]
pivotaldata/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated wi…   0                                       
pivotaldata/centos7-test           CentosOS 7 image for GPDB testing               0                                       
pivotaldata/centos7-build          CentosOS 7 image for GPDB compilation           0                                       
smartentry/centos                  centos with smartentry                          0                                       [OK]
jameseckersall/sonarr-centos       Sonarr on CentOS 7                              0                                       [OK]
  • NAME:倉(cāng)庫(kù)名稱(chēng)
  • DESCRIPTION:鏡像描述
  • STARS:用戶(hù)評(píng)價(jià),反應(yīng)一個(gè)鏡像的受歡迎程度
  • OFFICIAL:是否官方
  • AUTOMATED:自動(dòng)構(gòu)建,表示該鏡像由Docker Hub自動(dòng)構(gòu)建流程創(chuàng)建的

2、拉取鏡像

拉取鏡像默認(rèn)是從docker hub拉取,這是docker默認(rèn)的公用倉(cāng)庫(kù),不過(guò)缺點(diǎn)是國(guó)內(nèi)下載會(huì)比較慢。這里設(shè)置從ustc****拉取鏡像****(建議使用)。

在宿主機(jī)器編輯文件:vi /etc/docker/daemon.json,在該配置文件中加入(沒(méi)有該文件的話(huà),請(qǐng)先建一個(gè)):

{
 "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
img

最后,需要重啟docker服務(wù) systemctl restart docker.service 執(zhí)行拉取鏡像命令

[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
256b176beaff: Pull complete 
Digest: sha256:6f6d986d425aeabdc3a02cb61c02abb2e78e57357e92417d6d58332856024faf
Status: Downloaded newer image for centos:latest
img

3、列表鏡像

[root@localhost ~]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
docker.io/tomcat          latest              41a54fe1f79d        3 days ago          463 MB
docker.io/centos          latest              5182e96772bf        5 weeks ago         200 MB
  • REPOSITORY:鏡像所在的倉(cāng)庫(kù)名稱(chēng)
  • TAG:鏡像標(biāo)簽
  • lMAGE ID:鏡像ID
  • CREATED:鏡像的創(chuàng)建日期(不是獲取該鏡像的日期)
  • SIZE:鏡像大小

這些鏡像都是存儲(chǔ)在Docker宿主機(jī)的/var/lib/docker目錄下

img

4、刪除鏡像

[root@localhost ~]# docker rmi 41a54fe1f79d

3、Docker容器操作

操作 命令 說(shuō)明
運(yùn)行 docker run --name container-name -d image-nameeg:docker run –name myredis –d redis --name:自定義容器名-d:后臺(tái)運(yùn)行image-name:指定鏡像模板
列表 docker ps(查看正在運(yùn)行中的容器); docker ps -a:查看歷史運(yùn)行過(guò)的容器docker ps -l:查看最近運(yùn)行過(guò)的容器
停止 docker stop container-name/container-id 停止當(dāng)前你運(yùn)行的容器
啟動(dòng) docker start container-name/container-id 啟動(dòng)容器
刪除 docker rm container-id 刪除指定容器
端口映射 -p 6379:6379eg:docker run -d -p 6379:6379 --name myredis docker.io/redis -p: 主機(jī)端口(映射到)容器內(nèi)部的端口
容器日志 docker logs container-name/container-id
更多命令 https://docs.docker.com/engine/reference/commandline/docker/

1、啟動(dòng)容器

1)以交互方式啟動(dòng)容器:docker run -it --name 容器名稱(chēng) 鏡像 /bin/bash;

  • -i:表示以“交互模式”運(yùn)行容器
  • -t:表示容器啟動(dòng)后會(huì)進(jìn)入其命令行。加入這兩個(gè)參數(shù)后,容器創(chuàng)建就能登錄進(jìn)去。即分配一個(gè)偽終端。
  • --name :為創(chuàng)建的容器命名。
  • -v:表示目錄映射關(guān)系(前者是宿主機(jī)目錄,后者是映射到宿主機(jī)上的目錄),可以使用多個(gè)-v做多個(gè)目錄或文件映射。注意:最好做目錄映射,在宿主機(jī)上做修改,然后共享到容器上。
  • -d:在run后面加上-d參數(shù),則會(huì)創(chuàng)建一個(gè)守護(hù)式容器在后臺(tái)運(yùn)行(這樣創(chuàng)建容器后不會(huì)自動(dòng)登錄容器,如果只加-i -t兩個(gè)參數(shù),創(chuàng)建后就會(huì)自動(dòng)進(jìn)去容器)。
  • -p:表示端口映射,前者是宿主機(jī)端口,后者是容器內(nèi)的映射端口。可以使用多個(gè)-p做多個(gè)端口映射

創(chuàng)建一個(gè)交互式容器并取名為mycentos

[root@localhost docker]# docker run -i -t --name=mycentos centos /bin/bash
img

2)以守護(hù)進(jìn)程后臺(tái)方式啟動(dòng)容器:docker run -d --name 容器名稱(chēng) 鏡像

[root@localhost ~]# docker search tomcat                                       #搜索tomcat
[root@localhost ~]# docker pull tomcat                                         #拉取tomcat鏡像
[root@localhost ~]# docker run -d --name mytomcat -p 8888:8080 tomcat:latest   #啟動(dòng)tomcat容器,并做端口映射
[root@localhost ~]# docker  ps                                                 #查看容器運(yùn)行列表
img
img

2、停止容器

docker stop 容器名稱(chēng)或者容器ID

[root@localhost ~]# docker stop 62a021b1c0fd 
img

3、重啟容器

docker start 容器名稱(chēng)或者容器ID

[root@localhost ~]# docker start  62a021b1c0fd 

4、刪除容器

刪除容器必須是已經(jīng)停止的容器,刪除指定容器:docker rm 容器名稱(chēng)或者容器ID;刪除所有容器:docker rm ‘docker ps -a -q’

[root@localhost ~]# docker rm 62a021b1c0fd
img

以上參考:https://www.cnblogs.com/frankdeng/p/9275092.html

5、容器自啟

  1. 在創(chuàng)建容器的時(shí)候加參數(shù)

    docker run --restart=always
    
  2. 那已經(jīng)創(chuàng)建好了怎么辦呢?

    也不用擔(dān)心,運(yùn)行下面的命令

    docker update --restart=always 容器名[容器id]
    

    就可以實(shí)現(xiàn)容器的自動(dòng)啟動(dòng)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,501評(píng)論 6 544
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 99,673評(píng)論 3 429
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人,你說(shuō)我怎么就攤上這事。” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 178,610評(píng)論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我,道長(zhǎng),這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 63,939評(píng)論 1 318
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 72,668評(píng)論 6 412
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 56,004評(píng)論 1 329
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 44,001評(píng)論 3 449
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 43,173評(píng)論 0 290
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 49,705評(píng)論 1 336
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 41,426評(píng)論 3 359
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 43,656評(píng)論 1 374
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,139評(píng)論 5 364
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 44,833評(píng)論 3 350
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 35,247評(píng)論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 36,580評(píng)論 1 295
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 52,371評(píng)論 3 400
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 48,621評(píng)論 2 380