Getting Started with Docker: Install, Images, Containers, and Everyday Commands

Install Docker on your server from scratch, understand how images differ from containers, and learn the handful of commands you'll use every day.

Docker lets you package an application together with its runtime environment into a portable image, then run it on your server as a container — no more wrestling with dependencies or hand-tuning the host. This guide focuses on Ubuntu/Debian and walks you from installation all the way to daily operations.

Installing Docker

On your server or VPS, the quickest path is the official convenience script:

curl -fsSL https://get.docker.com | sh

If you'd rather install the official repository packages manually with apt:

sudo apt-get update
sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
  -o /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
  https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" \
  | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

> On Debian, just swap ubuntu for debian in the URLs above.

Verify the install, and add your user to the docker group so you don't have to prefix every command with sudo:

sudo docker run hello-world      # a welcome message means you're good
sudo usermod -aG docker $USER    # log out and back in to take effect

Images vs. Containers

This distinction is the key to understanding Docker:

  • Image: a read-only template bundling the app and its dependencies — think of an "install package" or a "class".
  • Container: a running instance of an image, writable and start/stoppable — think of a "process" or an "object".

One image can spawn any number of containers, and the image stays on your machine even after a container is stopped or removed.

Launching Your First Container

docker run pulls the image automatically if it isn't present locally, then starts a container. Using Nginx as an example:

docker run -d -p 8080:80 --name web nginx

The most common flags:

  • -d: run detached (in the background) so it doesn't tie up your terminal.
  • -p 8080:80: publish a port, mapping the host's 8080 to the container's 80.
  • -v /data/site:/usr/share/nginx/html: mount a volume, wiring a host directory into the container so data persists.
  • --name web: give the container a memorable name to use in later commands.

Now open http://YOURSERVERIP:8080 in a browser and you'll see the Nginx page.

Everyday Container Commands

docker ps                # list running containers
docker ps -a             # include stopped ones
docker logs -f web       # tail logs in real time (-f to follow)
docker exec -it web bash # open a shell inside the container
docker stop web          # stop the container
docker start web         # start it again
docker rm web            # remove it (stop it first)

docker exec -it is your go-to for troubleshooting: -it gives you an interactive terminal, and once inside you can inspect files and debug config just like on any Linux box.

Managing Images

docker pull redis:7      # pull a specific version (tag)
docker images            # list local images
docker rmi nginx         # remove an image (delete dependent containers first)

The :7 or :latest after an image name is its tag, used to distinguish versions. Omitting the tag defaults to latest, but in production you should pin an explicit version to avoid surprise updates.

Summary

Install via the official script or apt; remember that an image is the template and a container is the instance; use docker run with -d/-p/-v/--name to launch services; reach for ps/logs/exec/stop/rm for day-to-day management; and use pull/images/rmi to manage images. Master this small set of commands and you'll be able to deploy and operate containerized apps on your own server with confidence.