Official images
- Docker & Kubernetes course
- Beginner
- Lesson 69/82
- 4 min
Learn about official images and their security.
Official images
Official images (Docker Official Images) are images in the library/ namespace maintained together by Docker and the software's developers: nginx, postgres, python, node, redis... They get regular security updates, and their documentation explains the environment variables in detail.
docker run -d -e POSTGRES_PASSWORD=gizli postgres:16 # a documented variable
docker run -d -e MYSQL_ROOT_PASSWORD=gizli mysql:8Initialization scripts
Database images run the .sql and .sh files in the /docker-entrypoint-initdb.d/ folder on first start. This is the way to create the tables and load sample data automatically; it only runs while the data directory is empty:
docker run -d --name db -e POSTGRES_PASSWORD=gizli \
-v "$PWD/sema.sql":/docker-entrypoint-initdb.d/01-sema.sql:ro \
-v pgdata:/var/lib/postgresql/data postgres:16Practice A database with ready tables
Start a container named db from postgres:16 in the background: POSTGRES_PASSWORD=gizli; mount sema.sql from the current folder ("$PWD/sema.sql") read-only at /docker-entrypoint-initdb.d/01-sema.sql.
Starter code
# buraya yazExpected output
c5d6e7f8091a
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 In official image tags, what do suffixes like -slim, -alpine, -bookworm indicate?
- Processor speed
- The base operating system and size variant Correct answer
- The license
- The release date
Explanation: bookworm is the code name of Debian 12.
2 Mount the initialization script into the right folder.
-v "$PWD/sema.sql":/____/01-sema.sql:ro
-v "$PWD/sema.sql":/docker-entrypoint-initdb.d/01-sema.sql:ro
Explanation: Files in this folder run in name order.
3 Match.
| Term | Meaning |
|---|---|
postgres |
POSTGRES_PASSWORD |
mysql |
MYSQL_ROOT_PASSWORD |
initdb.d |
First-start scripts |
bookworm |
Debian 12 |