本文主要是介绍Ubuntu18 安装docker及部署nginx,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
安装docker
用官方提供的源太慢了,所以我采用了国内的阿里云源进行安装。
修改镜像源为阿里云源:
vim /etc/apt/sources.list
阿里云镜像源:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
更新软件索引:
apt-get update
安装依赖:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
安装GPG证书:
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
添加docker软件信息:
Sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
更新并安装docker-ce
sudo apt-get update
sudo apt-get install docker-ce
安装成功后使用docker version查看docker version查看版本信息
root@ubuntu:~# docker version
Client: Docker Engine - CommunityVersion: 19.03.13API version: 1.40Go version: go1.13.15Git commit: 4484c46d9dBuilt: Wed Sep 16 17:02:36 2020OS/Arch: linux/amd64Experimental: falseServer: Docker Engine - CommunityEngine:Version: 19.03.13API version: 1.40 (minimum version 1.12)Go version: go1.13.15Git commit: 4484c46d9dBuilt: Wed Sep 16 17:01:06 2020OS/Arch: linux/amd64Experimental: false
部署nginx
拉取官方nginx镜像
docker pull nginx
查看本地镜像
docker images
运行容器
docker run --name nginx-test -p 8080:80 -d nginx
参数说明:
–name nginx-test:容器名称。
-p 8080:80: 端口进行映射,将本地 8080 端口映射到容器内部的 80 端口。
-d nginx: 设置容器在在后台一直运行。
访问nginx
这篇关于Ubuntu18 安装docker及部署nginx的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!