1.环境准备:
centos 7.5 minal x86_64
docker-ce 18
2.更新系统: yum update -y && yum install net-tools vim wget git -y
3.安装必要的工具:
yum install -y yum-utils device-mapper-persistent-data lvm2
4. 添加docker-ce软件源 阿里云
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo && yum makecache fast
5.安装docker-ce,启动服务并加入开机启动
yum install docker-ce -y && systemctl start docker && systemctl enable docker
6.查看docker 信息:
docker info
7.加速docker:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://e721ea9e.m.daocloud.io
8.重启docker: systemctl restart docker
9.克隆postgres仓库 本来dockerfile自己写 为了偷懒就去下载个
git clone https://github.com/docker-library/postgres.git
此dockerfile 基于官方的Debian 国内下载很慢 所以需要换源
10.拉取一个基础镜像: docker pull debian
docker run -it debian /bin/bash
进入容器换源:apt-get update && apt-get install vim -y
vim /etc/apt/sources.list
填入以下内容:deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
然 apt-get update
exit
11.查看容器ID,将刚才的容器提交为新的镜像
docker ps -a
docker commit -m 'debian-aliyun' -a='merry' 78d7f313cb78 debian:aliyun
12.修改下载的dockerfile 基础镜像 为刚才提交的镜像
vim DockerFile
13.进入postgres 10 进行构建:
docker build -t postgres:10 .
14.验证镜像:docker images
15.启动一个容器:
docker run --name mypostgres_merry -d -p 5432:5432 -e POSTGRES_PASSWORD=123456 -e PGDATA=/data/ -e POSTGRES_USER=admin -e POSTGRES_DB=my_db postgres:10
16.本地登陆数据库:
psql --host=127.0.0.1 --username=admin --password --dbname=my_db
接下来的操作就算了吧,就是正常操作数据库!