- 1. docker的安装
- 1.1 官网的安装网站
- 1.2 阿里的镜像网站
- 2. 镜像参数
- 3.案列
- 3.1 镜像类
- 3.2 容器类
比较卡:https://docs.docker.com/engine/install/centos/
curl http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo curl -o /etc/yum.repos.d/CentOS-base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum install -y yum-utils device-mapper-persistent-data lvm2 yum list docker-ce.x86_64 --showduplicates | sort -r yum install -y docker-ce systemctl daemon-reload systemctl restart docker docker version docker info
配置镜像加速
阿里云Docker-hub https://cr.console.aliyun.com/cn-hangzhou/mirrors mkdir -p /etc/docker tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://uoggbpok.mirror.aliyuncs.com"] } EOF systemctl daemon-reload systemctl restart docker1.2 阿里的镜像网站
https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11sQ5GMq
2. 镜像参数镜像类参数:docker image
容器类,docker container
docker search centos docker pull centos:6.9 docker pull centos:7.5.1804 docker pull nginx docker image ls docker image inspect id docker image ls -q docker image save id >/tmp/ubuntu.tar docker image load -i /tmp/ubuntu.tar docker image tag id 名称:版本 docker image rm -f id
镜像的标识:
- REPOSITORY:TAG
centos:7.5.1804 - IMAGE ID (sha256:64位的号码,默认只截取12位)
82f3b5f3c58
交互式,退出及关闭 docker container run -it id 守护式 docker container run -d id docker containerls docker container ls -a 指定容器的名字 docker container run -it --name="yq" id docker container run -d --name="yq" id 端口映射 -p hostPort:containerPort -p ip:hostPort:containerPort -p ip::containerPort(随机端口:32768-60999) -p hostPort:containerPort/udp -p 81:80 –p 443:443 docker container run -it --name="yq" -p 8080:80 id 将书宿主机的8080端口映射到容器的80端口 docker run -P 80(随机端口) docker container run -d -p 8080:80 --name='n2' nginx:1.14 docker container run -d -p 10.0.0.100:8081:80 --name='n3' nginx:1.14 docker container run -d -p 80 --name='n5' nginx:1.14 docker container run -d -p 172.16.1.200::80 --name='n6' nginx:1.14 docker container stop id docker conatiner start id docker container dtart -i id docker container exec -it id /bin/bash 日志: docker logs id docker logs -tf id docker logs -tf --tail 10 id docker container top id cp,比较繁琐 docker container /opt/index.html n1:/usr/share/nginx/html -v docker container run -d -v /opt/html:/usr/share/nginx/html id 将宿主机的/opt/html与容器内部的nginx/html进行数据共享,类似于挂载 ,数据的持久化
容器后台及前台运行
1.ctrl+P,Q
attach 调用到前台
2.死循环,sleep 10000
3. 让程序一直运行,例如
docker container run -d --name="yq" id /usr/sbin/sshd -D
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)