PSQL In Docker - Danysoft · PSQL In Docker What is Docker? Why Containers? Why Not Use Virtual...
Transcript of PSQL In Docker - Danysoft · PSQL In Docker What is Docker? Why Containers? Why Not Use Virtual...
Confidential © 2016 Actian Corporation1 Confidential © 2016 Actian Corporation Version 0.2
PSQL In DockerLearn how to create and use PSQL containers using Docker.
Tom Bates, Principal Software Development Engineer, ActianActian Technical User Group ConferenceOctober 2016
Confidential © 2016 Actian Corporation2
This document is for informational purposes only and is subject to change at any time without notice. The information in this document is proprietary to Actian and no part of this document may be reproduced, copied, or transmitted in any form or for any purpose without the express prior written permission of Actian.
This document is not intended to be binding upon Actian to any particular course of business, pricing, product strategy, and/or development. Actian assumes no responsibility for errors or omissions in this document. Actian shall have no liability for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. Actian does not warrant the accuracy or completeness of the information, text, graphics, links, or other items contained within this material. This document is provided without a warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.
Confidential © 2016 Actian Corporation3
PSQL In Docker
What is Docker?
Why Containers?
Why Not Use Virtual Machines?
PSQL in a Docker Container
PSQL CLI in a Docker Container
PSQL PCC in a Docker Container
Demonstrations
Questions And Answers
Confidential © 2016 Actian Corporation4
Docker is one of the world's leading software containerization platforms.
Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run.
■ Code, runtime, system tools, system libraries.
■ Anything that can be installed on a server.
■ Guarantees that the software will always run the same, regardless of its environment.
Open.
■ Docker containers are based on open standards, enabling containers to run on all major Linux distributions, Mac OSX and Microsoft Windows.
What is Docker?
Confidential © 2016 Actian Corporation5
PSQL In Docker
What is Docker?
Why Containers?
Why Not Use Virtual Machines?
PSQL in a Docker Container
PSQL CLI in a Docker Container
PSQL PCC in a Docker Container
Demonstrations
Questions And Answers
Confidential © 2016 Actian Corporation6
Lightweight.
■ Containers running on a single machine share the same operating system kernel.
■ They start quickly and use less RAM.
■ Images are constructed from layered filesystems and share common files, making disk usage and image downloads much more efficient.
Secure by default.
■ Containers isolate applications from one another and the underlying infrastructure, while providing an added layer of protection for the application.
Why Containers?
Confidential © 2016 Actian Corporation7
PSQL In Docker
What is Docker?
Why Containers?
Why Not Use Virtual Machines?
PSQL in a Docker Container
PSQL CLI in a Docker Container
PSQL PCC in a Docker Container
Questions And Answers
Confidential © 2016 Actian Corporation8
Containers and virtual machines have similar resource isolation and allocation benefits but a different architectural approach.
■ Containers are more efficient.
Virtual machines include the application, the necessary binaries and libraries, and an entire guest operating system.
■ Can amount to tens of GBs.
Containers include the application and all of its dependencies but share the kernel with other containers.
■ They run as isolated processes in user space on the host operating system.
Why Not Use Virtual Machines?
Confidential © 2016 Actian Corporation9
PSQL In Docker
What is Docker?
Why Containers?
Why Not Use Virtual Machines?
PSQL CLI in a Docker Container
PSQL PCC in a Docker Container
PSQL in a Docker Container
Demonstrations
Questions And Answers
Confidential © 2016 Actian Corporation10
Docker Lifecycle.
1. Write a Dockerfile for a command.
2. Build an image from the Dockerfile.
3. Run the command in a new container.
4. Stop the running container.
5. Start the stopped container.
6. Remove the container.
7. Remove the image.
PSQL CLI in a Docker Container
Confidential © 2016 Actian Corporation11
The Dockerfile.
■ -
PSQL CLI in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation12
Build the image from the Dockerfile.
■ docker build --rm=true --force-rm -t psqlcli .
• -rm=true - Remove intermediate containers after a successful build.
• --force-rm - Always remove intermediate containers.
• -t - Name and optionally a tag in the 'name:tag' format.
• . - Path to the Dockerfile.
PSQL CLI in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation13
Run the command in a new container.
■ docker run --tty --interactive --attach=STDIN --attach=STDOUT --attach=STDERR --name psqlcli psqlcli
• --tty - Allocate a pseudo-TTY.
• --interactive - Keep STDIN open even if not attached.
• --attach - Attach to STDIN, STDOUT or STDERR.
• --name - Assign a name to the container.
• psqlcli - The image.
■ -
PSQL CLI in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation14
Run the command in a new container (cont’d).
■ -
PSQL CLI in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation15
Stop the running container.
■ docker stop psqlcli
Start the stopped container.
■ docker start -i -a psqlcli
• -i - Attach container's STDIN.
• -a - Attach STDOUT/STDERR and forward signals.
■ -
Remove the container.
■ docker rm psqlcli
PSQL CLI in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation16
Remove the image.
■ docker rmi psqlcli
PSQL CLI in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation17
PSQL In Docker
What is Docker?
Why Containers?
Why Not Use Virtual Machines?
PSQL CLI in a Docker Container
PSQL PCC in a Docker Container
PSQL in a Docker Container
Demonstrations
Questions And Answers
Confidential © 2016 Actian Corporation19
Build the image from the Dockerfile.
■ docker build --rm=true --force-rm -t pcc .
Run the command in a new container.
■ docker run --name pcc -e DISPLAY=:0 -v /tmp/.X11-unix/X0:/tmp/.X11-unix/X0 pcc
• -e - Set environment variables.
• -v - Bind mount a volume.
PSQL PCC in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation20
Run the command in a new container (cont’d).
■ -
PSQL PCC in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation21
Run the command in a new container (cont’d).
■ -
PSQL PCC in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation22
Stop the running container.
■ docker stop pcc
PSQL PCC in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation23
Start the stopped container.
■ docker start pcc
■ -
PSQL PCC in a Docker Container (cont’d)
State is retained.
Confidential © 2016 Actian Corporation24
Remove the container.
■ docker rm pcc
Remove the image.
■ docker rmi pcc
PSQL PCC in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation25
PSQL In Docker
What is Docker?
Why Containers?
Why Not Use Virtual Machines?
PSQL CLI in a Docker Container
PSQL PCC in a Docker Container
PSQL in a Docker Container
Demonstrations
Questions And Answers
Confidential © 2016 Actian Corporation27
The Docker Command - “run_psql”.
■ -
PSQL in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation28
The Docker Command - “run_psql” (cont’d).
■ -
PSQL in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation29
Build the image from the Dockerfile.
■ docker build --rm=true --force-rm -t psql .
Run the command in a new container.
■ docker run --detach --name psql -p 1583:1583 -p 3351:3351 -e license= psql
• --detach - Run container in background and print container ID.
• -p - Publish a container's port(s) to the host.
■ -
PSQL in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation30
Stop the running container.
■ docker stop psql
Start the stopped container.
■ docker start psql
Remove the container.
■ docker rm psql
Remove the image.
■ docker rmi psql
PSQL in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation31
Attach to the container.
■ docker attach --sig-proxy=false psql
• --sig-proxy - Proxy all received signals to the process.
■ -
PSQL in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation32
Run a command in a running container.
■ docker exec –i -t psql bash
• -i - Keep STDIN open even if not attached.
• -t - Allocate a pseudo-TTY.
■ -
PSQL in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation33
What’s the container’s IP address?
■ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' psql
• --format - Format the output using the given go template.
■ -
PSQL in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation34
List the images.
■ docker images --all
• --all - Show all images (default hides intermediate images)
■ -
List the containers.
■ docker ps --all
• --all - Show all containers (default shows just running)
■ -
PSQL in a Docker Container (cont’d)
Confidential © 2016 Actian Corporation35
PSQL In Docker
What is Docker?
Why Containers?
Why Not Use Virtual Machines?
PSQL CLI in a Docker Container
PSQL PCC in a Docker Container
PSQL in a Docker Container
Demonstrations
Questions And Answers
Confidential © 2016 Actian Corporation36
PSQL In Docker
What is Docker?
Why Containers?
Why Not Use Virtual Machines?
PSQL CLI in a Docker Container
PSQL PCC in a Docker Container
PSQL in a Docker Container
Demonstrations
Questions And Answers