青岛海诚
Focus on technology

导航

 

Ubuntu 18.04安装docker 以及Nginx服务设置

1.安装需要的包
sudo apt install apt-transport-https ca-certificates software-properties-common curl


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"


3.添加成功后更新软件包缓存
sudo apt update


4.安装 Docker-ce
sudo apt install docker-ce


5.设置开机自启动并启动 Docker-ce(安装成功后默认已设置并启动,可忽略)
sudo systemctl enable docker
sudo systemctl start docker


6.测试运行
sudo docker run hello-world

7.添加当前用户到 docker 用户组,可以不用 sudo 运行 docker(可选)
sudo groupadd docker
sudo usermod -aG docker $USER

 

Nginx

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 terminal

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/
posted on 2018-10-23 16:16  青岛海诚  阅读(157)  评论(0编辑  收藏  举报