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

 

posted on 2018-08-12 19:53  jafic  阅读(1969)  评论(0编辑  收藏  举报