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

Windows 10 安装 Docker

 

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

开启 Windows 系统的 Hyper-V 和 容器 功能

启动 Docker

启动 Docker

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

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

[code lang=text]
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.
(amd64)
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:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

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

注意

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

[code lang=text]
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>
[/code]

  1. 基于 image 启动一个 container

[code lang=text]
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
4fa0e575eccf23c65b76463ba0f0f782d2ac84294971217b1bbb2b264b8fe001
PS C:\tmp>
[/code]

  1. 列出当前正在运行的 container

[code lang=text]
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 0.0.0.0:5432->5432/tcp postgresql_database
[/code]

  1. PostgreSQL 10 已经启动,可以尝试连接上去做操作了;这里使用其自带的 psql 来操作

[code lang=text]
PS C:\tmp> docker exec -it postgresql_database /bin/bash
bash-4.2$ psql
psql (10.1)
Type “help” for help.
[/code]

[code lang=text]
postgres=# \q
bash-4.2$ exit
exit
PS C:\tmp>
[/code]

如无特殊说明,文章均为本站原创,转载请注明出处
源自: 王明军的博客
本文链接地址: Docker 初体验:Windows 10 安装 Docker 后体验 PostgreSQL 10
广告

Categories: 默认目录, PostgreSQL

Tagged as: , ,

发表评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.