1.安裝須要的包
sudo apt install apt-transport-https ca-certificates software-properties-common curlhtml
2.添加 GPG 密鑰,並添加 Docker-ce 軟件源,這裏仍是以中國科技大學的 Docker-ce 源爲例
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable"linux
3.添加成功後更新軟件包緩存
sudo apt updatenginx
4.安裝 Docker-ce
sudo apt install docker-cedocker
5.設置開機自啓動並啓動 Docker-ce(安裝成功後默認已設置並啓動,可忽略)
sudo systemctl enable docker
sudo systemctl start dockerubuntu
6.測試運行
sudo docker run hello-world緩存
7.添加當前用戶到 docker 用戶組,能夠不用 sudo 運行 docker(可選)
sudo groupadd docker
sudo usermod -aG docker $USERapp
Nginxcurl
1.拉取 nginx鏡像
sudo docker pull nginx測試
2.運行鏡像
sudo docker run -d -p 80:80 nginx
註釋
-d means let the application runs in the backgroup which will be not closed even you close the terminalurl
3.訪問localhost check is it ok
4.建一個本身的html
sudo docker run -d -p 8088:80 -v $PWD/httpfiles:/usr/share/nginx/html nginx
httpfiles是你的文件目錄
再次訪問localhost:8088 check
linux經常使用語句:
ls:列出目錄
touch xxx.html 新建文件
cd..返回上一級
docker經常使用語句:
1.獲取鏡像docker pull2.查看鏡像信息docker images3.列出容器docker ps4.中止docker stop5.啓動docker start