Docker 初体验:Windows 10 安装 Docker 后体验 PostgreSQL 10

Windows 10 安装 Docker

首先,需要开启 Windows 系统的 Hyper-V容器 功能,见下图所示。

其次,到 Install Docker for Windows 下载 Docker Community Edition for Windows
然后,双击安装包按照提示安装即可,安装完成后启动 Docker,可在任务栏处查看其图标。

最后,打开 Windows PowerShell,依次键入 docker --versiondocker run hello-world,验证安装完成。

PS C:\tmp> docker --version
Docker version 18.03.1-ce, build 9ee9f40
PS C:\tmp>
PS C:\tmp> docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:

For more examples and ideas, visit:

PS C:\tmp> docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              e38bc07ac18e        4 weeks ago         1.85kB


Windows 10 之前的版本需要 Docker Toolbox,具体请查阅 Docker官方文档 或者 Docker Toolbox overview

Requires Microsoft Windows 10 Professional or Enterprise 64-bit. For previous versions get Docker Toolbox.

体验 PostgreSQL 10

Docker 官方 PUBLIC REPOSITORY 中已经提供了大量的 image,可以在网页中搜索 PostgreSQL,也可以在 Windows PowerShell 中使用命令 docker search 搜索目标 image
PostgreSQL 10 的 image 在这里,相关描述、配置都可以在网页描述中找到。
1. 获取 image

PS C:\tmp> docker pull centos/postgresql-10-centos7
Using default tag: latest
latest: Pulling from centos/postgresql-10-centos7
469cfcc7a4b3: Pull complete
0a5f3b508bac: Pull complete
b9f4a8f01dc6: Pull complete
e23d825f7248: Pull complete
b8a71558a6c3: Pull complete
863454303679: Pull complete
c3f2a37dfd0e: Pull complete
ba1b37ec97a6: Pull complete
3494aae457aa: Pull complete
Digest: sha256:70223753ea9da9dbbe6b3a11169fc598ca5adfa341d9cd3881e7d621f5139460
Status: Downloaded newer image for centos/postgresql-10-centos7:latest
PS C:\tmp>
  1. 基于 image 启动一个 container
PS C:\tmp> docker run -d --name postgresql_database -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DA TABASE=db -p 5432:5432 centos/postgresql-10-centos7
PS C:\tmp>
  1. 列出当前正在运行的 container
PS C:\tmp> docker ps
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES
4fa0e575eccf        centos/postgresql-10-centos7   "container-entrypoin…"   7 minutes ago       Up 7 minutes>5432/tcp   postgresql_database
  1. PostgreSQL 10 已经启动,可以尝试连接上去做操作了;这里使用其自带的 psql 来操作
PS C:\tmp> docker exec -it postgresql_database /bin/bash
bash-4.2$ psql
psql (10.1)
Type "help" for help.
postgres=# \q
bash-4.2$ exit
PS C:\tmp>

分类:Default, PostgreSQL

Tagged as: , ,


Fill in your details below or click an icon to log in: 徽标

您正在使用您的 账号评论。 注销 /  更改 )

Twitter picture

您正在使用您的 Twitter 账号评论。 注销 /  更改 )

Facebook photo

您正在使用您的 Facebook 账号评论。 注销 /  更改 )

Connecting to %s

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理