Docker: Difference between revisions

Jump to navigation Jump to search
Reworked page for more legible scribbles then before.
No edit summary
(Reworked page for more legible scribbles then before.)
Docker is a container solution for any operating system. Docker containers can run as a user, allowing for rootful and rootless containers, allowing for more security.
 
== Concepts: ==
Images - A built software on top of a slim operating system, made into a prebuilt image ready for download
 
Environment variables - static settings for the container.
 
== Installation ==
Debian 12 installation:
Debian 12 install:<syntaxhighlight lang="bash" line="1">
 
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
 
sudo apt-get install docker docker-compose
</syntaxhighlight>
 
== Common Docker Commands: ==
 
Keep in mind what permission level you are running containers in. Rootful containers will need sudo level permissions.<syntaxhighlight lang="bash">
Common Docker Commands:
docker compose:--help
 
</syntaxhighlight>Lists docker's commands and syntax.<syntaxhighlight lang="bash">
Keep in mind what permission level you are running containers in. Rootful containers will need sudo level permissions.
 
docker container --help
 
docker container ls
docker container killls -a
</syntaxhighlight>Specifies we are working with containers, --help lists every action. ls lists all containers the user is running. -a lists all containers for the user.<syntaxhighlight lang="bash">
docker container logsstop (container_name)
docker container restart (container_name)
docker container kill (container_name)
docker container logs (container_name)
docker container rm -f (container_name)
</syntaxhighlight>Stop, restart, and kill a container. Logs prints the logs in terminal. rm deletes the container from docker, -f force removing.
 
== Docker Compose: ==
docker container kill
Compose simplifies docker down to files instead of commands, allows for full stacks to be built in a single file. Docker can then pull all images specified and build the container accordingly with one command.
 
docker container logs
 
Docker Compose:
 
simplifies docker down to files instead of commands, allows for full stacks to be built in a single file. Docker can then pull all images specified and build the container accordingly with one command.
 
regular docker command:
 
Regular docker command:<syntaxhighlight lang="bash" line="1" start="0">
'''sudo docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest'''
</syntaxhighlight>Sudo is ran as the Portainer container is privileged as it binds to docker.sock . -d runs the container in the background, -p specifies a port, --restart defines the restart policy, see above. -v defines a volume, can also define a file to be passed in. The image is defined at the end.
 
Create a folder for Portainer to live in ~/Portainer and create docker-compose.yaml:<syntaxhighlight lang="bash">
docker compose:
mkdir Portainer
cd Portainer
touch docker-compose.yaml
nano docker-compose.yaml
</syntaxhighlight><syntaxhighlight lang="yaml" line="1">
services:
portainer:
image: portainer/portainer-ce:latest
container_name: portainer
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /Path/To/portainer_data:/data
ports:
- 8000:8000
- 9443:9443
restart: always
</syntaxhighlight>Pull the listed images from docker's repositories and run the services listed: <syntaxhighlight lang="bash">
sudo docker-compose pull
sudo docker-compose up -d
</syntaxhighlight>Sudo is used here as Portainer binds to docker.sock. -d runs the compose container(s) in the background.
6

edits

Navigation menu