乐趣区

关于docker:Dockerdocker环境搭建dockercompose环境搭建

一、docker 环境搭建

1.docker 装置

# 更新 yum 源
yum update -y
#装置 docker
yum list installed | grep docker
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache fast
yum install -y docker-ce-18.09.6-3.el7 docker-ce-cli-18.09.6-3.el7 containerd.io-1.2.0-3.el7
systemctl start docker
systemctl enable docker // 开机自启动 

2.docker 降级
docker 降级 镜像下载地址

# 下载 docker-ce-XXX
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.09.6-3.el7.x86_64.rpm
# 降级 docker-ce
yum -y upgrade ./docker-ce-18.09.6-3.el7.x86_64.rpm
# 装置 docker-ce
yum install ./docker-ce-18.09.6-3.el7.x86_64.rpm

3.docker 移除

yum list installed | grep docker
yum -y remove docker-engine.x86_64
rm -rf /var/lib/docker

二、docker-compose 环境搭建

1. 装置 docker-compose

curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
## 可能会报错,curl: (35) Peer reports incompatible or unsupported protocol version. 执行  yum update -y nss curl libcurl
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version

2.docker-compose 启动

# 启动 利用
docker-compose up -d
#查看
docker-compose ps
#增加利用
docker-compose create
#查看日志
docker-compse logs -f <server-name>

三、docker 容器治理

1. 镜像创立并推送

# 依据容器提交镜像到本地
docker commit -m "add image" -a 'tt' 37bb image-name
# 依据生成的镜像打 tag
docker tag image-name 111.01.1.6/public/image-name:base1.0
#如果镜像仓库须要登录,则进行登录
docker login 111.01.1.6 
# 推送镜像
docker push 111.01.1.6/public/image-name:base1.0

2. 对于配置镜像仓库

# 解决报错 Error response from daemon: Get https://192.168.208.40:10050/v1/\_ping: http: server gave HTTP response to HTTPS client
# 1. 查看引入的镜像仓库地址
cat /etc/docker/daemon.json
#1. 增加镜像仓库地址
echo '{"insecure-registries":["111.01.1.6","111.01.1.2"] }' > /etc/docker/daemon.json
# 2. 重启 docker
systemctl restart docker

四、docker 常用命令

退出移动版