[root@tar1 yum.repos.d]# docker pull postgres:11.511.5: Pulling from library/postgres9fc222b64b0a: Pull complete38296355136d: Pull complete2809e135bbdb: Pull complete77907400401d: Pull complete1f8ceea7d21e: Pull complete1ede1f2cb1b8: Pull completedcfbc2751885: Pull complete8379f81b7622: Pull complete08034f3aaedc: Pull completecb6db97b313d: Pull complete7a41d1ed6f3b: Pull complete15f5a1254505: Pull complete5a9451e12286: Pull complete55bb5e2d55ba: Pull completeDigest: sha256:f766d03bb49c7dd16fe32c1eb2645d13cb315adc029557cd1e4a0a9c094933d5Status: Downloaded newer image for postgres:11.5
下载要花费一定的时间。
[]postgres 11.5 c3fe76fef0a6 9 days ago 312MB[]
下载成功以后,可以查看镜像的信息(包括大小)。
[]2) --name 指定创建的容器的名字;
[]CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESccb3d0bb1a30 postgres:11.5 "docker-entrypoint..." 37 seconds ago Up 36 seconds 5432/tcp, 0.0.0.0:54322->54333/tcp dockerPG11
[root@tar1 yum.repos.d]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESccb3d0bb1a3 postgres:11.5 "docker-entrypoint..." 14 minutes ago Up 14 minutes 5432/tcp, ...:54322->54333/tcp dockerPG113b8d602037b4 hello-world "/hello" About an hour ago Exited () About an hour ago jolly_wrightc5cdfc83f7bd hello-world "/hello" About an hour ago Exited () About an hour ago elegant_edison
[root@tar1yum.repos.d]# docker logs ccb3d0bb1a303e081fac20622c0b821b71720308280a8d1a55b906e792fe6452The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.utf8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /var/lib/postgresql/data ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting default timezone ... Etc/UTCselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... okSuccess. You can now start the database server using:pg_ctl -D /var/lib/postgresql/data -l logfile startWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.waiting for server to start....2019-08-23 09:48:02.765 UTC [39] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"2019-08-23 09:48:02.791 UTC [40] LOG: database system was shut down at 2019-08-23 09:48:01 UTC2019-08-23 09:48:02.797 UTC [39] LOG: database system is ready to accept connectionsdoneserver started/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*waiting for server to shut down....2019-08-23 09:48:02.846 UTC [39] LOG: received fast shutdown request2019-08-23 09:48:02.849 UTC [39] LOG: aborting any active transactions2019-08-23 09:48:02.852 UTC [39] LOG: background worker "logical replication launcher" (PID 46) exited with exit code 12019-08-23 09:48:02.852 UTC [41] LOG: shutting down2019-08-23 09:48:02.881 UTC [39] LOG: database system is shut downdoneserver stoppedPostgreSQL init process complete; ready for start up.2019-08-23 09:48:02.967 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 54322019-08-23 09:48:02.967 UTC [1] LOG: listening on IPv6 address "::", port 54322019-08-23 09:48:02.973 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"2019-08-23 09:48:02.989 UTC [48] LOG: database system was shut down at 2019-08-23 09:48:02 UTC2019-08-23 09:48:02.996 UTC [1] LOG: database system is ready to accept connections
[root@tar1 yum.repos.d]# docker exec -it dockerPG11 bashroot@ccb3d0bb1a30:/#
:/# ps -ef |grep postpostgres 1 0 0 09:47 ? 00:00:00 postgrespostgres 49 1 0 09:48 ? 00:00:00 postgres: checkpointerpostgres 50 1 0 09:48 ? 00:00:00 postgres: background writerpostgres 51 1 0 09:48 ? 00:00:00 postgres: walwriterpostgres 52 1 0 09:48 ? 00:00:00 postgres: autovacuum launcherpostgres 53 1 0 09:48 ? 00:00:00 postgres: stats collectorpostgres 54 1 0 09:48 ? 00:00:00 postgres: logical replication launcherroot 69 55 0 10:10 ? 00:00:00 grep post
root@ccb3d0bb1a30:/# su - postgrespostgres@ccb3d0bb1a30:~$postgres@ccb3d0bb1a30:~$
postgres@ccb3d0bb1a30:~$ psql -d postgrespsql (11.5 (Debian 11.5-1.pgdg9+1))Type "help" for help.postgres=#
[root@tar1 ~]# netstat -ntlActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 0 0 127.0.0.1:25 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:111 0.0.0.0:* LISTENtcp 0 0 192.168.122.1:53 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:22 0.0.0.0:* LISTENtcp 0 0 127.0.0.1:631 0.0.0.0:* LISTENtcp6 0 0 ::1:25 :::* LISTENtcp6 0 0 :::111 :::* LISTENtcp6 0 0 :::54322 :::* LISTENtcp6 0 0 :::22 :::* LISTENtcp6 0 0 ::1:631
-bash-4.2$ psql -U postgres -h localhost -p 54322用户 postgres 的口令:psql (11.5)输入 "help" 来获取帮助信息.postgres=#
postgres=# select version();version----------------------------------------------------------------------------------PostgreSQL 11.5 (Debian 11.5-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit(1 行记录)postgres=#
postgres=# CREATE TABLE weather (postgres(# city varchar(80),postgres(# temp_lo int, -- low temperaturepostgres(# temp_hi int, -- high temperaturepostgres(# prcp real, -- precipitationpostgres(# date datepostgres(# );CREATE TABLEpostgres=# INSERT INTO weather VALUES ('San Francisco',46,50,0.25, '1994-11-27');INSERT 0 1postgres=# INSERT INTO weather (city, temp_lo, temp_hi, prcp, date) VALUES ('San Francisco', 43, 57, 0.0, '1994-11-29');INSERT 0 1postgres=# INSERT INTO weather (date, city, temp_hi, temp_lo) VALUES ('1994-11-29', 'Hayward', 54, 37);INSERT 0 1postgres=# SELECT * FROM weather;city | temp_lo | temp_hi | prcp | date---------------+---------+---------+------+------------San Francisco | 46 | 50 | 0.25 | 1994-11-27San Francisco | 43 | 57 | 0 | 1994-11-29Hayward | 37 | 54 | | 1994-11-29(3 行记录)postgres=#postgres=# \dt关联列表架构模式 | 名称 | 类型 | 拥有者----------+---------+--------+----------public | weather | 数据表 | postgres(1 行记录)
docker stop ccb3d0bb1a30ccb3d0bb1a30是实例(容器)的ID或者(dockerPG11是容器的名字)docker stop dockerPG11
[]dockerPG11
[]总用量 32drwxr-xr-x. 3 root root 19 8月 23 23:46 cf103a7ead15ff3e25f42e83703f06544cfbf018fe469d577002dff9f692bb6f-rw-------. 1 root root 65536 8月 25 12:13 metadata.db[]cf103a7ead15ff3e25f42e83703f06544cfbf018fe469d577002dff9f692bb6f[]总用量 32-rw-------. 1 root root 65536 8月 25 12:32 metadata.db[]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69917105/viewspace-3145461/ ,如需转载,请注明出处,否则将追究法律责任。