9/26/2023 0 Comments Docker postgres create database![]() Of course our postgres1 container is still running. ![]() Now we can quit from psql with \q and exit from our shell mydb=# \q Then we'll insert a row into the table: mydb=# INSERT INTO people (id,name) VALUES (1, 'Mark') Īnd finally, check it's there mydb=# SELECT * FROM people We'll create a table: mydb=# CREATE TABLE people (id int, name varchar(80)) Now let's do something a bit more interesting. We'll also ask for the database version, and the current date: mydb=# \l Now inside psql, let's run some basic commands. # createdb -U postgres mydbĪnd then let's launch the psql utility which is a CLI tool for PostgreSQL, connected to our mydb database: # psql -U postgres mydb Inside that shell we can ask it to create a new database with the name mydb. This saves us from needing to have any tools to connect to and manage PostgreSQL databases installed locally. We'll create a database and one easy way to do that is by using docker exec to launch an interactive shell running inside our postgres1 container, which has the PostgreSQL CLI tools installed. Once we've done this we can check it's running with docker psĪnd view the log output with docker logs postgres1 docker run -d -p 5432:5432 -v postgres-data:/var/lib/postgresql/data ` PostgreSQL stores its data in /var/lib/postgresql/data, so we're mounting our volume to that path. The volume name will be postgres-data, and Docker will automatically create it (just using storage on the Docker host's local disk) if a volume with this name doesn't already exist. We're running detached ( -d) mode (so in the background).īut we're also going to mount a volume (with -v), which will be used to store the database we create. We'll use docker run to start a new container from the official postgres image with the name postgres1 and exposing port 5432 (the PostgreSQL default). But another great option is Play with Docker which lets us run all these commands in the browser. If you're running Docker for Windows put it in Linux mode. You can follow along with the commands in this tutorial if you have Docker installed. Today we're going to look at PostgreSQL which will give us an opportunity to see Docker volumes in action. Last time we looked at Redis, and that gave us the opportunity to see the docker run and docker exec commands in action. This is the second part of a series looking at how easy Docker makes it to explore and experiment with open source software.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |