docker
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| docker [February 18, 2026 at 03:28] – yanevskiv | docker [May 16, 2026 at 14:56] (current) – Ivan Janevski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | # docker | ||
| + | |||
| + | ## What is docker? | ||
| + | **Docker** is a tool for managing containers. Containers are somewhat like virtual machine instances except a lot more lightweight. | ||
| + | |||
| + | Think of an application e.g. a web app. You want to run the application, | ||
| + | |||
| + | What does it take to run an application in a virtual machine? First, you first need to set up a virtual machine. This means giving it a slice of your hardware (CPU, RAM, HDD, ...). Then, you need to install an OS on the virtual machine (let's say, Ubuntu). Then, you also need to install everything the application needs (`apt install ...`). Finally, you need to copy your application inside the virtual machine. This works, but wastes a lot of resources + the application will obviously be a lot slower than it would have been if it was ran on the host. | ||
| + | |||
| + | What if instead of emulating hardware, we just run the application we wanted on the host, but somehow made the application " | ||
| + | |||
| + | But actually, it's even better! Not only can we make an application " | ||
| + | |||
| + | Therefore, it's actually more appropriate to think of Docker as an " | ||
| + | |||
| + | ## Install | ||
| + | Follow the guide on https:// | ||
| + | |||
| + | On Debian and Ubuntu systems, this usually boils down to modifying `/ | ||
| + | ```bash | ||
| + | $ sudo apt update | ||
| + | $ sudo apt install | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | ``` | ||
| + | |||
| + | If you want to make a regular user be able to use `docker` command, just add them to the `docker` group: | ||
| + | ``` | ||
| + | $ sudo gpasswd -a john docker | ||
| + | $ sudo groups john | ||
| + | john : john docker | ||
| + | ``` | ||
| + | Remember that they will have to log out and then log back in, in order for their groups to update. | ||
| + | |||
| + | ## Practice | ||
| + | In order to see what Docker is in practice, it's best if you try it yourself: | ||
| + | ``` | ||
| + | docker run -it --rm ubuntu: | ||
| + | ``` | ||
| + | This puts you inside a container, running bash shell as root. You can now use `apt` to install anything you like. You can also break the system if you like (e.g. run `rm -rf /usr`). When you exit the shell, everything you ever did inside is lost. This includes anything you installed, but also anything you created, edited, changed, removed, or broke. | ||
| + | |||
| + | When you run `docker run -it --rm ubuntu: | ||
| + | |||
| + | But what if you **do** want to preserve what you've installed? That's where `docker commit` and `docker build` commands come in, but that comes later. | ||
| + | |||
| + | ## Concepts | ||
| + | ### Images | ||
| + | Docker images are predefined environments. You run an application within these predefined environments with `docker run -it --rm < | ||
| + | |||
| + | Docker images are pulled from https:// | ||
| + | |||
| + | Continuing on the virtual machine analogy, you can think of a docker image as `.iso` file, containing OS installation + system configuration. Running a container is then somewhat like starting a virtual machine, installing an OS with that `.iso`, then running a desired application within that OS. | ||
| + | |||
| + | Docker images are stored in `/ | ||
| + | |||
| + | The following are some image related commands you should remember: | ||
| + | |||
| + | - `docker run -it --rm < | ||
| + | - `docker images` - List docker images on your local filesystem | ||
| + | - `docker rmi < | ||
| + | - `docker pull < | ||
| + | - `docker search < | ||
| + | - `docker tag < | ||
| + | |||
| + | ### Containers | ||
| + | Docker containers are particular instances of an image. You run a container with `docker run -it --rm < | ||
| + | |||
