docker安装
环境: 阿里云 ubuntu16.04 _x64 root 用户权限
参考教程
1、查看环境,更新 apt 包索引。我喜欢root用户
apt-get update
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-get -y update
apt-get -y install docker-ce
2、有一条更简单的命令
这里Linus是我的用户名
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
usermod -aG docker linus
安装完毕后,下载Ubuntu镜像,我选择最新的,因为它很小,压缩后大约20多M
Ubuntu 镜像库地址
docker pull ubuntu:latest
查看镜像,docker images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest bb0eaf4eee00 16 hours ago 72.9MB
运行和查看
linus@ubuntu:~$ docker run -itd --name ubuntu-test ubuntu /bin/bash
67bd4c63a9a58f8cc6b08be53a736c7d46a02844afa6a3d01bfc3861ff02a0d2
linus@ubuntu:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
67bd4c63a9a5 ubuntu "/bin/bash" 11 seconds ago Up 10 seconds ubuntu-test
停止运行
linus@ubuntu:~$ docker stop ubuntu-test
ubuntu-test
3、重新制作镜像–安装gosu
docker gosu 官网链接,进去寻找我们需要的Dockerfile
从这里看,简单明了,真是好用,复制下来
创建目录
#创建docker目录,方便管理
mkdir docker
cd docker/
mkdir ubuntu
#vim 创建复制保存wq退出
vim ubuntu/latest.Dockerfile
# auto generated
# docker build -t gosu/ubuntu:latest -f ubuntu/latest.Dockerfile .
FROM ubuntu:latest
COPY --from=gosu/assets /opt/gosu /opt/gosu
RUN set -x \
&& /opt/gosu/gosu.install.sh \
&& rm -fr /opt/gosu
#运行,这个过程怎么好说,我第一次用ubuntu14.04只花了几分钟,这次用ubuntu:latest耗时很久
docker build -t gosu/ubuntu:latest -f ubuntu/latest.Dockerfile .
#查看镜像
dockers images