第四篇:Docker安裝並啓動一個http容器

知識背景

官方文檔:https://docs.docker.com/engine/installation/

docker分爲社區版(CE)和企業版(EE),他們最大的區別就是:社區版是開源免費的,企業版是收費的。
對於想要學習docker容器、或者小型開發團隊來說,首選Docker社區版.

1.卸載掉老版本的Docker容器

yum remove docker  docker-common   docker-selinux    docker-engine

2.有三種Docker CE安裝方法

a.使用docker鏡像,便於安裝和升級,推薦使用這種方法

b.下載Docker的rpm包來安裝,很有可能遇到依賴包問題

c.在測試和開發環境,可以選擇自動化腳本安裝Docker

3.使用鏡像倉庫安裝

a.如果首次安裝Dcoker CE ,需要設置Docker安裝源

yum install -y yum-utils device-mapper-persistent-data lvm2

說明:數據持久化設備和lvm2需要映射器所需的驅動程序支持

b.執行下面的命令設置穩定的鏡像源

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

4.安裝Docker CE

yum install -y  docker-ce

5.如果你是在生產環境安裝Docker,需要指定相應的版本來安裝,而不是安裝最新的Docker

使用下面命令可列出現鏡像倉庫中Docker鏡像版本,並使用sort工具對Docker版本從高到低進行一個排序

[root@docker ~]# yum list docker-ce --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
Installed Packages
* epel: mirror.lzu.edu.cn
docker-ce.x86_64            17.12.0.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos            @docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable
Available Packages

說明:指定安裝Docker版本時,舉個列子,使用下面命令安裝

yum install <FULLY-QUALIFIED-PACKAGE-NAME>

6.設置Docker開機啓動

systemctl enable docker.service

systemctl start docker.service

7.驗證docker是否安裝成功安裝,如果返回如下信息,表示docker安裝成功

第四篇:Docker安裝並啓動一個http容器

8.在docker容器安裝httpd服務,並把宿主機的80端口映射給httpd的80端口

[root@docker ~]# docker run -d -p 80:80 httpd
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
f49cf87b52c1: Pull complete
02ca099fb6cd: Pull complete
de7acb18da57: Pull complete
770c8edb393d: Pull complete
0e252730aeae: Pull complete
6288e83d58fa: Pull complete
a91ad03b2178: Pull complete
Digest: sha256:643ca2ed9f6caf1f392184aee05a8f2cd478bdacbd350ea6b4dbc8f5b8e400a8
Status: Downloaded newer image for httpd:latest
0747f02bb2304ef964ed153e6e81f3f083965f95f12ad9a70c95b7f329243a2c
docker: Error response from daemon: driver failed programming external connectivity on endpoint mystifying_jennings (8644011e3dab6725c314f6e634444ca6b6cfe3792d6f504a12af2e065d4c448f): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use.

安裝後在web頁面輸入宿主機地址訪問http容器

第四篇:Docker安裝並啓動一個http容器

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章