Docker Install Linux
This chapter covers how to run common Linux distribution containers with Docker, including Ubuntu, Alpine, and CentOS.
Ubuntu Container
Pull and Run
bash
docker pull ubuntu:24.04
docker run -it --name my-ubuntu ubuntu:24.04 /bin/bash
docker run -d --name ubuntu-server ubuntu:24.04 tail -f /dev/nullCommon Operations
bash
docker exec -it my-ubuntu /bin/bash
apt-get update && apt-get upgrade -y
apt-get install -y curl wget vim net-toolsCustom Ubuntu Image
dockerfile
FROM ubuntu:24.04
RUN apt-get update && \
apt-get install -y curl wget vim git net-tools && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
CMD ["/bin/bash"]Alpine Container
Alpine Linux is an extremely lightweight distribution, ideal as a Docker base image.
Pull and Run
bash
# Alpine image is only ~5MB
docker pull alpine:3.19
docker run -it --name my-alpine alpine:3.19 /bin/shPackage Management
Alpine uses the apk package manager:
bash
apk update
apk add curl wget vim git
apk search nginx
apk del curlCustom Alpine Image
dockerfile
FROM alpine:3.19
RUN apk update && \
apk add --no-cache curl wget bash && \
rm -rf /var/cache/apk/*
CMD ["/bin/bash"]Image Size Comparison
| Image | Size |
|---|---|
| alpine:3.19 | ~5 MB |
| ubuntu:24.04 | ~78 MB |
| debian:12 | ~116 MB |
CentOS Container
⚠️ CentOS 8 reached EOL in 2021. Consider CentOS Stream, Rocky Linux, or AlmaLinux as alternatives.
Pull and Run
bash
docker pull quay.io/centos/centos:stream9
docker run -it --name my-centos quay.io/centos/centos:stream9 /bin/bash
# Or use Rocky Linux (CentOS alternative)
docker pull rockylinux:9
docker run -it --name my-rocky rockylinux:9 /bin/bashPackage Management
bash
dnf update -y
dnf install -y curl wget vim git net-toolsPractical Scenarios
Testing Different Linux Environments
bash
docker run -it --rm ubuntu:24.04 bash -c "cat /etc/os-release"
docker run -it --rm alpine:3.19 sh -c "cat /etc/os-release"
docker run -it --rm rockylinux:9 bash -c "cat /etc/os-release"Setting Up a Development Environment
bash
docker run -it \
--name dev-env \
-v $(pwd):/workspace \
-w /workspace \
ubuntu:24.04 /bin/bashChapter Summary
Running Linux distribution containers with Docker is straightforward and great for development, testing, and learning. Alpine is the preferred base image for production due to its minimal size.