ubuntu docker Ubuntu 18.04安裝docker 以及Nginx服務設置

Ubuntu 18.04安裝docker 以及Nginx服務設置

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 dockershell


6.測試運行
sudo docker run hello-worldubuntu

7.添加當前用戶到 docker 用戶組,能夠不用 sudo 運行 docker(可選)
sudo groupadd docker
sudo usermod -aG docker $USER緩存

 

Nginxbash

1.拉取 nginx鏡像
sudo docker pull nginxapp


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 terminalcurl

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 pull
2.查看鏡像信息
docker images
3.列出容器
docker ps
4.中止
docker stop
5.啓動
docker start

 

 

 

參考:解決 Docker pull 出現的net/http: TLS handshake timeout 的一個辦法

問題:

執行

$ sudo docker run hello-world

時出現:

Unable to find image 'hello-world:latest' locally docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: net/http: TLS handshake timeout. See 'docker run --help'.

緣由:

不可描述。

解決辦法:

使用國內的Docker倉庫daocloud:

$ echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=http://f2d6cb40.m.daocloud.io\"" | sudo tee -a /etc/default/docker $ sudo service docker restart

解決問題:

root@ubuntu:/home/wasdns# sudo docker run hello-worldUnable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 78445dd45222: Pull complete Digest: sha256:7820f4620e6cf3e795643fac2f6b09e7fd0a29e7e5c4eee6aac9ba0bedca158c Status: Downloaded newer image for hello-world:latest 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. 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://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
相關文章
相關標籤/搜索