Docker安装

curl -fsSL get.docker.com -o  get-docker.sh  && sudo sh  get-docker.sh
wget http://files.wanlf.vip/usr/local/docker/get-docker.sh  && sudo sh  get-docker.sh

查看与启动docker

//查看docker版本
sudo docker version
//启动docker
sudo systemctl start docker

docker简要命令

docker info
docker image --help
docker image ls 
docker container ls 
docker container rm #container可省略
docker container run nginx #拉取nginx镜像并启动 
docker container stop xxx
docker container ps -a
docker run nginx
docker container run -p 80:80 nginx

docker 批量操作

//全部停止
docker container stop $(docker container ps -aq)
docker container rm -f $(docker container ps -aq)
docker container rm xxx -f //强制删除

docker 启动

docker run -d -p 80:80 nginx  //-d 后台启动
docker attach containerid  //前台启动
docker logs  -f containerid //查看日志 -f 动态跟踪
docker container run -it ubuntu sh  //-it交互式启动
docker container run -d -p 80:80 nginx
docker exec -it xxx sh  //进入容器
docker container run -it busybox sh
ip a //查看地址
docker container top 31 //查看容器的进程
ps aux|grep nginx //查看进程
pstree -halps 1908 //查看进程层级关系

docker 镜像

docker image pull nginx
docker pull nginx:1.20.0
docker image pull quay.io/bitnami/nginx
docker image inspect  88736fe82739  //查看镜像详情
docker image rm 
docker image save nginx:1.20.0 -o  nginx.image //镜像保存
docker image load -i nginx.image

dockerfile基本结构

FROM ubuntu:20.04
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y python3.9 python3-pip python3.9-dev
ADD hello.py /
CMD ["python3", "/hello.py"]
//开始构建
docker image build -t hello:1.1 .  
docker run -it hello:1.1
docker image rm xiaopeng163/hello:1.0
docker image tag hello:1.1  wanlf/hello:1.0  //改名字

docker镜像上传

docker login    #id password
docker image push 
docker image push 781776053/hello:1.0   //tag名字要和账号对应
docker image pull  781776053/hello:1.0
docker run -it 781776053/hello:1.0
docker container commit 884 781776053/hello:1.0  //通过容器创建对象
docker container run -it 781776053/hello:1.0  python3 /hello.py