What is Docker?
Docker runs programs inside containers. A container is like a lunch box. It holds one program and everything that program needs. You can move it to another server and it works the same way.
An image is the recipe for a container. You download an image, then start a container from it.
Steps
- Log in to your server with SSH. SSH lets you type commands on a remote computer.
- Update the package list and install a few helper tools.
apt update apt install -y ca-certificates curl - Create a folder for the Docker signing key. The key proves the software really comes from Docker.
install -m 0755 -d /etc/apt/keyrings - Download the key.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc chmod a+r /etc/apt/keyrings/docker.asc - Add the Docker software source.
This tells Ubuntu where to find Docker.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" | tee /etc/apt/sources.list.d/docker.list > /dev/null - Refresh the package list again.
apt update - Install Docker.
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin - Check that Docker is running.
systemctl status docker - Run a test container.
Docker downloads a tiny image and prints a welcome message.docker run hello-world
Handy commands
docker pslists running containers.docker imageslists downloaded images.docker stop NAMEstops a container.
Tip: To use Docker without typing
sudo, add your normal user to the docker group with usermod -aG docker USERNAME. Then log out and log in again. Only give this to people you trust, because it gives strong power over the server.Quick recap
- Docker runs programs in containers.
- Add the Docker software source, then install with apt.
- Test with
docker run hello-world. - Use
docker psto see what is running.