├── LICENSE ├── README.md └── pgadmin.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Jedd Dryden 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dockerfile Snippets 2 | 3 | These snippets are tested on `debian:bookworm` based images. 4 | They should help save time when creating Dockerfiles, especially for [VS Code Dev Containers](https://code.visualstudio.com/docs/devcontainers/containers). 5 | 6 | ### Other Pages 7 | 8 | - [pgAdmin](pgadmin.md) 9 | 10 | ### Contributing 11 | 12 | If you have any suggestions or improvements, please feel free to open an issue or pull request. 13 | Useful snippets are always welcome. 14 | 15 | ## Table of Contents 16 | 17 | - [Dockerfile Snippets](#dockerfile-snippets) 18 | - [Other Pages](#other-pages) 19 | - [Contributing](#contributing) 20 | - [Table of Contents](#table-of-contents) 21 | - [Install PostgreSQL](#install-postgresql) 22 | - [Update and Upgrade Packages](#update-and-upgrade-packages) 23 | - [Install Common Packages](#install-common-packages) 24 | - [Install Zsh/Oh My Zsh](#install-zshoh-my-zsh) 25 | - [Install Node.js and NPM](#install-nodejs-and-npm) 26 | - [Install Docker with Host Socket](#install-docker-with-host-socket) 27 | 28 | 29 | ## Install PostgreSQL 30 | 31 | ```Dockerfile 32 | ###################################### 33 | ### START # Install PostgreSQL ####### 34 | ###################################### 35 | 36 | # Set PostgreSQL version 37 | ARG POSTGRESQL_MAJOR=16 38 | 39 | # Install Dependencies 40 | RUN apt install -y wget 41 | 42 | # Create the file repository configuration: 43 | RUN sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' 44 | 45 | # Import the repository signing key: 46 | RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - 47 | 48 | # Update the package lists: 49 | RUN apt update 50 | 51 | # Install PostgreSQL. 52 | RUN apt -y install postgresql-${POSTGRESQL_MAJOR} 53 | 54 | # Set locale 55 | ENV LC_ALL=C 56 | 57 | # Set postgres password 58 | RUN service postgresql start && \ 59 | su -c "psql -c \"ALTER USER postgres PASSWORD 'postgres';\"" - postgres && \ 60 | service postgresql stop 61 | 62 | # Allow remote connections 63 | RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/16/main/pg_hba.conf && \ 64 | echo "listen_addresses='*'" >> /etc/postgresql/16/main/postgresql.conf && \ 65 | sed -i 's/local all postgres peer/local all postgres md5/' /etc/postgresql/16/main/pg_hba.conf 66 | 67 | ``` 68 | 69 | To start the server, these commands can be used with a shell script entrypoint: 70 | 71 | ```bash 72 | # Adjust ownership 73 | chown -R postgres:postgres /var/lib/postgresql/16/main 74 | 75 | # Start the postgres server 76 | service postgresql start 77 | 78 | # Tail the PostgreSQL log file to keep the container running 79 | tail -f /var/log/postgresql/postgresql-16-main.log 80 | ``` 81 | 82 | These commands could also be added to the Dockerfile if you prefer. 83 | 84 | ## Update and Upgrade Packages 85 | 86 | ```Dockerfile 87 | ################################## 88 | ### START # Update and Upgrade ### 89 | ################################## 90 | 91 | RUN apt update \ 92 | && apt upgrade -y 93 | 94 | ################################## 95 | ### END # Update and Upgrade ##### 96 | ################################## 97 | ``` 98 | 99 | ## Install Common Packages 100 | 101 | ```Dockerfile 102 | ####################################### 103 | ### START # Install Common Packages ### 104 | ####################################### 105 | 106 | RUN apt install -y build-essential curl wget git vim nano unzip zip gnupg2 apt-transport-https ca-certificates lsb-release software-properties-common 107 | 108 | ####################################### 109 | ### END # Install Common Packages ##### 110 | ####################################### 111 | ``` 112 | 113 | ## Install Zsh/Oh My Zsh 114 | 115 | ```Dockerfile 116 | ##################################### 117 | ### START # Install Zsh/Oh My Zsh ### 118 | ##################################### 119 | 120 | # Base install of Zsh with Oh My Zsh 121 | RUN apt install -y zsh \ 122 | && sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended 123 | 124 | # Install Zsh plugins 125 | RUN git clone https://github.com/zsh-users/zsh-autosuggestions $HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions \ 126 | && git clone https://github.com/zsh-users/zsh-syntax-highlighting $HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting \ 127 | && git clone https://github.com/zsh-users/zsh-history-substring-search $HOME/.oh-my-zsh/custom/plugins/zsh-history-substring-search 128 | 129 | # Configure Zsh to use plugins 130 | RUN sed -i 's/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting zsh-history-substring-search history aliases sudo themes docker nmap kubectl)/' $HOME/.zshrc \ 131 | && sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="af-magic"/' $HOME/.zshrc 132 | 133 | # Set Zsh as default shell 134 | RUN chsh -s /usr/bin/zsh 135 | 136 | ##################################### 137 | ### END # Install Zsh/Oh My Zsh ##### 138 | ##################################### 139 | ``` 140 | 141 | ## Install Node.js and NPM 142 | 143 | You can change the `NODE_MAJOR` argument to the version you want to install. 144 | 145 | ```Dockerfile 146 | ####################################### 147 | ### START # Install Node.js and NPM ### 148 | ####################################### 149 | 150 | ARG NODE_MAJOR=20 151 | 152 | RUN set -uex; \ 153 | mkdir -p /etc/apt/keyrings; \ 154 | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \ 155 | | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \ 156 | echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" \ 157 | > /etc/apt/sources.list.d/nodesource.list; \ 158 | apt -y update; \ 159 | apt -y install nodejs; 160 | 161 | ####################################### 162 | ### END # Install Node.js and NPM ##### 163 | ####################################### 164 | ``` 165 | 166 | ## Install Docker with Host Socket 167 | 168 | ```Dockerfile 169 | ############################################### 170 | ### START # Install Docker with Host Socket ### 171 | ############################################### 172 | 173 | # Set docker host socket 174 | ENV DOCKER_HOST=unix:///var/run/docker-host.sock 175 | 176 | # Install Docker 177 | RUN apt install -y lsb-release \ 178 | && curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - \ 179 | && echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \ 180 | && apt update \ 181 | && apt install -y docker-ce docker-ce-cli containerd.io 182 | 183 | # Add user to docker group if it doesn't exist and add user to it 184 | RUN if getent group docker > /dev/null 2>&1; then \ 185 | echo "Docker group exists"; \ 186 | else \ 187 | groupadd docker; \ 188 | fi \ 189 | && usermod -aG docker root 190 | 191 | ############################################### 192 | ### END # Install Docker with Host Socket ##### 193 | ############################################### 194 | ``` 195 | 196 | If you are using this for a VS Code devcontainer, you should add the following to your `.devcontainer/devcontainer.json` file to allow the container to access the host socket: 197 | 198 | ```json 199 | "mounts": [ 200 | "source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind" 201 | ] 202 | ``` 203 | 204 | If you are using the `docker-compose.yml` file to allow the container to access the host socket, you can instead add the following to your `docker-compose.yml` file under the `volumes` section if the container: 205 | 206 | ```yaml 207 | volumes: 208 | - /var/run/docker.sock:/var/run/docker-host.sock 209 | ``` -------------------------------------------------------------------------------- /pgadmin.md: -------------------------------------------------------------------------------- 1 | # pgAdmin 2 | 3 | Some notes on [`dpage/pgadmin4`](https://hub.docker.com/r/dpage/pgadmin4/) images. 4 | 5 | The full documentation is [here](https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html). 6 | 7 | ## Table of Contents 8 | 9 | - [pgAdmin](#pgadmin) 10 | - [Table of Contents](#table-of-contents) 11 | - [Essential environment variables](#essential-environment-variables) 12 | - [Removing login screen](#removing-login-screen) 13 | - [Removing master password](#removing-master-password) 14 | - [Adding servers](#adding-servers) 15 | 16 | ## Essential environment variables 17 | 18 | ```yaml 19 | PGADMIN_DEFAULT_EMAIL: 'user@example.com' 20 | PGADMIN_DEFAULT_PASSWORD: 'password' 21 | ``` 22 | 23 | ## Removing login screen 24 | 25 | The pgAdmin container comes with a login screen by default, this can by bypassed by setting the following enviroment variables: 26 | 27 | ```yaml 28 | PGADMIN_CONFIG_SERVER_MODE: 'False' 29 | ``` 30 | 31 | ## Removing master password 32 | 33 | The pgAdmin container comes with a master password by default, this can by bypassed by setting the following enviroment variables: 34 | 35 | ```yaml 36 | PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False' 37 | ``` 38 | 39 | ## Adding servers 40 | 41 | Servers can be added by overridding the [`servers.json`](https://www.pgadmin.org/docs/pgadmin4/development/import_export_servers.html#json-format) file at `/pgadmin4/servers.json` with: 42 | 43 | ```json 44 | { 45 | "Servers": { 46 | "1": { 47 | "Name": "Server Name", 48 | "Group": "Servers", 49 | "Port": 5432, 50 | "Username": "postgres", 51 | "Host": "db", 52 | "MaintenanceDB": "postgres", 53 | "SSLMode": "prefer", 54 | "PassFile": "/pgpass" // Omit if not using password authentication 55 | } 56 | } 57 | } 58 | ``` 59 | 60 | If you are using password authentication, you will need to mount a [`pgpass`](https://www.postgresql.org/docs/current/libpq-pgpass.html) file into the container at `/pgpass` with the following format: 61 | 62 | ```yaml 63 | # hostname:port:database:username:password 64 | db:5432:postgres:postgres:postgres 65 | ``` --------------------------------------------------------------------------------