docker学习
docker 安装
旧版本卸载
apt-get remove docker docker-engine docker.io containerd runc
使用apt安装docker
// 更新数据源
apt-get update
//安装所需依赖
apt-get -y 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 -
//新增数据源
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
//更新并安装docker
apt-get update && apt-get install -y docker-ce
//验证安装
docker version
使用脚本自动安装docker
//从阿里云镜像安装docker
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh --mirror Aliyun
ubutnu16.04安装docker
https://www.cnblogs.com/hupeng1234/p/9773770.html
ubuntu18.04安装docker
https://www.jianshu.com/p/23ad5f0b7510
docker镜像加速器配置
通过修改daemon配置文件 /etc/docker/daemon.json来使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://n5y95k29.mirror.aliyuncs.com"]
}
EOF
//重启Docker
systemctl daemon-reload
systemctl restart docker
//验证配置是否成功
docker info
基本使用
vi Dockerfile
#文件内容
FROM tomcat:latest
COPY index.jsp /usr/local/tomcat/webapps/ROOT
#构建自定义镜像
docker build -t myshop .
/*
.的目的
1.在当前目录找到Dockerfile配置文件
2.指定我Dockefile的上下文目录(打包当前目录传输给dockerserver)
*/
dockerfile其他指令
dockerCompose 学习
dockerCompose安装
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
验证
docker-compose --version
使用准备
修改ip
vi /etc/netplan/50-cloud-init.yaml
#
network:
ethernets:
ens33:
addresses: [192.168.255.132/24]
gateway4: 192.168.255.2
nameservers:
addresses: [192.168.255.2]
version: 2
#生效
netplan apply
修改主机名
vi /etc/cloud/cloud.cfg
#允许更改主机名生效
preserve_hostname: true
# 设置hostname
hostnamectl set-hostname deployment
#查看
hostnamectl
#配置hosts
cat >> /etc/hosts <<EOF
192.168.255.132 deployment
EOF
修改DNS
vi /etc/systemd/resolved.conf
#
[Resolve]
DNS=114.114.114.114
简单使用
#创建/usr/local/docker/tomcat
#创建docker-compose.yml
version: '3.1'
services:
tomacat:
restart: always
image: tomcat
container_name: tomcat
ports:
- 8080:8080
读书 docker 入门
运行docker 自带的hello world
docker run hello-world
运行容器
docker -i -t ubuntu /usr/bin/bash
容器命名
docker run --name bob_the_brother -it ubuntu /usr/bin/bash
重新启动已经停止的容器
//通过命名
docker start bob_the_brother
//通过id
docker start <id>
进入已经运行的容器
docker attach bob_the_brother
创建守护容器
docker run -d <container> -name daemon_dave
获取容器日志
docker logs daemon_dave
# -f 循环读取
# -t 时间戳
容器日志驱动
docker run --log-driver="syslog" --name daemon_dave -d ubuntu /usr/bin/bash
## 查看守护式容器的进程
```shell
docker top daemon_dave
查看容器的统计状态信息
docker stats daemon_dave
在容器内部运行任务
# 容器内部运行后台
docker exec -d daemon_dave touch /etc/new_config_file
# 容器内部运行交互任务
docker exec -t -i daemon_dave /bin/bash
停止守护容器
docker stop daemon_dave
docker stop <id>
自动重启容器
docker run --restart=always --name daemon_dave -d ubuntu /bin/bash
# 指定重启次数
--restart=on-failure:5
深入容器
查看容器象析信息
docker inspect daemon_dave
删除容器
docker rm <id>
# 删除所有容器
docker rm `docker ps -a -q`
docker 镜像
列出镜像
docker images
拉取镜像
docker pull ubuntu:12.04
# 查看指定镜像
docker pull images ubuntu
在docker hub上查找镜像
docker search puppet
提交定制容器
docker commit <id> 镜像仓库/镜像名
-m 提交信息
-a 作者信息
使用Dockerfile构建
I'm a fucKing fake coder!

浙公网安备 33010602011771号