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/