This guide provides a quick reference for getting started with Docker on Ubuntu. Docker is a platform for developing, shipping, and running applications in containers.
Install Docker on Ubuntu:
sudo apt update
sudo apt install docker.io
sudo usermod -aG docker $USER
Logout and login to apply group changes.
Run a simple hello-world container to test the installation:
docker run hello-world
Create a Dockerfile and build a custom image:
# Dockerfile
FROM ubuntu:latest
RUN apt update && apt install -y nginx
CMD ["nginx", "-g", "daemon off;"]
Build the image:
docker build -t my-nginx-image .
FROM
: Specifies the base image. RUN
: Executes commands during image build. CMD
or ENTRYPOINT
: Specifies the default command to run when the container starts. docker ps
: List running containers. docker ps -a
: List all containers (including stopped ones). docker stop
: Stop a running container. docker start
: Start a stopped container. docker rm
: Remove a stopped container. docker network ls
: List Docker networks. docker network create
: Create a new network. docker run --network= ...
: Connect a container to a network. docker volume ls
: List Docker volumes. docker volume create
: Create a new volume. Create a docker-compose.yml
file for multi-container applications:
version: '3'
services:
web:
image: nginx:latest
db:
image: postgres:latest
Run the services:
docker-compose up
docker tag my-nginx-image username/my-nginx-image
docker push username/my-nginx-image
docker system prune
: Remove unused data (containers, networks, volumes, etc.). docker image prune
: Remove dangling images. Go back to Docker Guide.
Visit other Developer Guides.