Docker: Difference between revisions

From wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
[[Category:Linux/Unix]]
[[Category:Linux/Unix]]
I started with docker as that is the name I knew at that time. Moved to [[Podman]] as that should be more secure and light-weight. Most information is in the [[Podman]] page.
Docker is used to create containers. In a container system resources are separated from each other e.g. to create a development environment where the developer can experiment freely without the risk of jeopardizing the host system.
Docker is used to create containers. In a container system resources are separated from each other e.g. to create a development environment where the developer can experiment freely without the risk of jeopardizing the host system.


Line 21: Line 23:
</syntaxhighlight>
</syntaxhighlight>


;docker build -t <name>:<tag> /etc/docker
;<nowiki>docker build -t <name>:<tag> /etc/docker</nowiki>
:This builds the image with a name and a tag
:This builds the image with a name and a tag
;docker image ls
;docker image ls
Line 34: Line 36:
;docker system prune
;docker system prune
:Delete unused images and build caches
:Delete unused images and build caches
;docker prune -a
;docker system prune -a
:Delete unused images and all build cache
:Delete unused images and all build cache

Latest revision as of 09:48, 25 July 2025

I started with docker as that is the name I knew at that time. Moved to Podman as that should be more secure and light-weight. Most information is in the Podman page.

Docker is used to create containers. In a container system resources are separated from each other e.g. to create a development environment where the developer can experiment freely without the risk of jeopardizing the host system.

A dockerfile defines what will be in the docker image, running the image will create a container.

Installation
apt install docker.io
apt install docker-buildx
This creates a working container with a python virtual environment
Dockerfile in /etc/docker
FROM debian
LABEL name="Hans de Ridder"
RUN apt-get update
RUN apt-get -y install python3-full
RUN python3 -m venv /home/ubuntu/venv
ENV PATH="/home/ubuntu/venv/bin:$PATH"
RUN pip install pandas
CMD ["echo", "I'm alive"]
docker build -t <name>:<tag> /etc/docker
This builds the image with a name and a tag
docker image ls
List all existing images
docker run -v <hostdir>:<containerdir> -it <image ID> bash
Create the container and open a bash prompt in it. When leaving the shell the container is closed
This way you can run any command in a container that only exists while the command is running.
<hostdir> is mounted on <containerdir> which will be created automatically
docker ps -a
List all containers
docker system prune
Delete unused images and build caches
docker system prune -a
Delete unused images and all build cache