This guide provides instructions for creating and using a minimal Ubuntu Docker image tailored for development purposes.
To create a minimal Ubuntu Docker image, use the official Ubuntu base image and minimize the installed packages. Here's a basic Dockerfile:
# Use an official minimal Ubuntu base image
FROM ubuntu:20.04
# Update package lists
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
build-essential \
curl \
ca-certificates \
git \
x11-apps \
&& rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR /app
FROM
: Specifies the official minimal Ubuntu base image. RUN
: Updates package lists, upgrades installed packages, and installs essential development tools and X11-apps for display. Build the Docker image from the Dockerfile:
docker build -t minimal-ubuntu-dev .
Run a container from the built image:
docker run -it --name minimal-ubuntu-container -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v /local/folder/:/docker_workspace/folder/ minimal-ubuntu-dev
Inside the container, you have a minimal Ubuntu environment with essential development tools. Customize the Dockerfile to add additional tools or packages as needed.
To enter a running container:
docker exec -it minimal-ubuntu-container bash
To copy files from the host machine to a running container:
docker cp /path/to/local/file minimal-ubuntu-container:/app
To attach and use the display with the container:
xhost +local:docker
This allows the container to access the X server on the host.
Go back to Docker Guide.
Visit other Developer Guides.