Docker: Difference between revisions

From wiki
Jump to navigation Jump to search
Created page with "Category:Linux/Unix 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 :Dockerfile in /etc..."
 
No edit summary
 
(2 intermediate revisions 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 8: Line 10:
  apt install docker-buildx
  apt install docker-buildx


;This creates a working container
;This creates a working container with a python virtual environment
:Dockerfile in /etc/docker  
:Dockerfile in /etc/docker  
<syntaxhighlight lang=text>
<syntaxhighlight lang=text>
FROM ubuntu
FROM debian
LABEL name="Hans de Ridder"
LABEL name="Hans de Ridder"
RUN apt-get update
RUN apt-get update
CMD ["bash", "-i"]
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"]
</syntaxhighlight>
</syntaxhighlight>


;docker build /etc/docker
;<nowiki>docker build -t <name>:<tag> /etc/docker</nowiki>
:This build the image
:This builds the image with a name and a tag
;docker image ls
;docker image ls
:List all existing images
:List all existing images
;docker run -it <image ID>
;<nowiki>docker run -v <hostdir>:<containerdir> -it <image ID> bash</nowiki>
:Create the container and open a bash prompt in it. When leaving the shell the container is closed
: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

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