Docker: Difference between revisions
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 |
||
| Line 8: | Line 8: | ||
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 | FROM debian | ||
LABEL name="Hans de Ridder" | LABEL name="Hans de Ridder" | ||
RUN apt-get update | RUN apt-get update | ||
CMD [" | 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 | ;docker build -t <name>:<tag> /etc/docker | ||
:This | :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 prune -a | |||
:Delete unused images and all build cache | |||
Revision as of 20:33, 21 July 2025
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 prune -a
- Delete unused images and all build cache