[ad_1]
Run Applications with Docker, Part 3: Integrate Container Apps with Docker Compose
Tom shows how to deploy PostgreSQL and pgAdmin from files using Docker Compose.
Docker has been around for about ten years now, during which time it has become a standard tool in many production and test environments. Previously, I wrote a series of articles (start here) that explored the basics of Docker. The current series explores how to run applications on Docker.
So far, we’ve focused on using PostgreSQL, a powerful and popular free and open source database. In his last two articles, he deployed Docker images from the command line. psql (a command-line front end for PostgreSQL) to interact with the database and write scripts to complete repetitive tasks on the database.
But where Docker really shines is that you can build and deploy multiple Docker images to create multi-tier applications. This article uses Docker Compose to deploy PostgreSQL and pgAdmin from files.
What is pgAdmin?
pgAdmin is an application used to interact with and manage PostgreSQL. It uses a browser as her GUI front end, allowing local and remote users to interact. pgAdmin has a devoted following and is the most popular open source administration tool for PostgreSQL. It is actively developed and supports advanced features such as two-factor authentication.
Docker Compose
Docker Compose was specifically designed to help define and share multi-container applications. After creating a YAML file that specifies the image to deploy, you can launch this file ( docker-compose.yml) to deploy the application.
First, you need to install Docker Compose on your system. To do this, I typed:
Apt-install docker-composer
Below is the YAML file used to deploy PostgreSQL and pgAdmin in this article.
version: "3.8" services: postgresdb: image: postgres:12.2 container_name: PostgreSQL restart: always environment: POSTGRES_DB: postgres POSTGRES_USER: admin POSTGRES_PASSWORD: MyPassword PGDATA: /var/lib/postgresql/data volumes: - pgsql-data:/var/lib/postgresql/data ports: - 5010:5432 pgadmin: image: dpage/pgadmin4:4.18 container_name: pgAdmin restart: always environment: PGADMIN_DEFAULT_EMAIL: [email protected] PGADMIN_DEFAULT_PASSWORD: MyPassword PGADMIN_LISTEN_PORT: 80 ports: - 5011:80 volumes: - pgadmin-data:/var/lib/pgadmin links: - postgresdb:pgsql-server volumes: pgsql-data: pgadmin-data:
Below is a breakdown of the information contained in the YAML file.
- version Indicates the version of Docker Compose to use. This should match the Docker version you are using.
- service Points to the deployed container. The two containers deployed in this case are PostgreSQL and pgAdmin. These images are known to work together, so we list specific versions of these images instead of the latest.
- of service The section describes how to deploy the container.
- of volume The section describes volumes used by containers.
Although not used in this example, the network can also be written to a file. This is a quick overview of the YAML file. See the official documentation for details.
of docker-compose.yml You have to put it in another directory and then run it. To do this, I typed:
mkdir pgAdminPostgres mv docker-compose.yml pgAdminPostgres cd pgAdminPostgres docker-compose up -d
of docker-compose up -d The command runs everything in the background.
I verified that the container was deployed by typing docker ps -a.
I then stopped the container to remove the instance and confirmed it was removed by typing:
docker-compose down docker ps -a
This command also shows previous instances of PostgreSQL (postgresql01) Confirm that the down command had no effect.
Using pgAdmin
After restarting the environment, I typed http://10.0.0.17:5011/ into my web browser. 10.0.0.17 is the IP address of the Docker host and 5011 This is the port described in the YAML file.
On the login screen, [email protected] When my passwordThese values were written in a YAML file.
The next page informed me that I wasn’t running the latest version of pgAdmin.
clicked add new server icon and entered the name of the PostgreSQL instance (PostgreSQL), username (administrator), and password (my password).
In the left navigation menu,[データベースとテーブルスペース]and expand Dashboard tab.
Then I right clicked database and chosen Create > Database.
This brought up a wizard that allowed me to create a new database.I expanded the new database’s scheme and right clicked tablecreated a new table (test table).
You can also create a new column in the table by right clicking columnFurther use of the interface is beyond the scope of this article. However, if you need more information, please refer to its usage guide.
Conclusion
The advantage of using Docker Compose is that you can quickly create and destroy environments. This is useful not only in testing, but also in production. For example, if you need to do regression testing, you can launch an older version of your multi-tier application with a single command. In production, you can launch a new environment. If something goes wrong, you can revert to the older version just as quickly. In the next article on Docker, we’ll take it further by using Docker Compose to deploy other versions of our application.
About the author
Tom Fenton has extensive hands-on IT experience in a variety of technologies over the last 25 years, with a focus on virtualization and storage for the last 15 years. He currently works for ControlUp as his technical marketing manager. Previously, he worked at VMware where he was a senior he was a course developer, solution engineer and competitive marketing group. He also worked at Taneja Group as a Senior Validation Engineer, leading the Validation Services Lab and helping launch the vSphere Virtual Volumes practice. He is on Twitter @vDoppler.
[ad_2]
Source link