Docker Basic Setup: Difference between revisions

From WikiMLT
m (Стадий: 3 [Фаза:Разработване, Статус:Разутвърден]; Категория:Linux Server)
 
(32 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>{{ContentArticleHeader/Linux Server|toc=off}}{{ContentArticleHeader/Containers|toc=off}}{{ContentArticleHeader/DevOps_and_SRE}}</noinclude>
<noinclude>{{ContentArticleHeader/Linux Server|toc=off}}{{ContentArticleHeader/Containers|toc=off}}{{ContentArticleHeader/DevOps_and_SRE|toc-limit=2}}</noinclude>
 
== Docker Installation Steps ==
This section we gives fresh (Feb. 2023) references how to install Docker and Docker Compose plugin v.2.x on Ubuntu.
 
* Docker Docs: [https://docs.docker.com/engine/install/ubuntu/ Install Docker Engine on Ubuntu] >> Uninstall old versions >> Install using the repository
* Docker Docs: [https://docs.docker.com/compose/install/linux/#install-using-the-repository Install the Compose plugin] >> Install using the repository
* LinuxServer.io Docs: [https://docs.linuxserver.io/general/container-execution As an additional Docker usage reference and source of plenty of images]
 
{{collapse/begin}}
== Deprecated Docker Installation Steps ==
{{collapse/div|#Deprecated Installation Steps}}
=== Install Docker ===


== Install Docker ==
Install Docker on Ubuntu and other Debian based distros.<syntaxhighlight lang="shell" line="1">
Install Docker on Ubuntu and other Debian based distros.<syntaxhighlight lang="shell" line="1">
sudo apt install docker.io curl
sudo apt install docker.io curl
Line 11: Line 22:
*Collabora.com:  [https://www.collabora.com/news-and-blog/blog/2018/07/04/docker-io-debian-package-back-to-life/ The docker.io Debian package is back to life]
*Collabora.com:  [https://www.collabora.com/news-and-blog/blog/2018/07/04/docker-io-debian-package-back-to-life/ The docker.io Debian package is back to life]


== Install Docker Compose ==
=== Install Docker Compose ===
More information at [https://docs.docker.com/compose/gettingstarted/ Get started with Docker Compose].<syntaxhighlight lang="bash" class="mlw-continue">
 
More information at [https://docs.docker.com/compose/gettingstarted/ Get started with Docker Compose].<syntaxhighlight lang="bash" class="code-continue">
# docker-compose from github.com/docker/compose#where-to-get-docker-compose
# docker-compose from github.com/docker/compose#where-to-get-docker-compose
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="shell" line="1" class="mlw-continue">
<syntaxhighlight lang="shell" line="1" class="code-continue">
sudo curl -L --fail \
sudo curl -L --fail \
https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64 \
https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64 \
Line 25: Line 37:
Alternatively, for example, one can use [https://docs.linuxserver.io/general/docker-compose Docker-compose provided by Linuxserver.io].
Alternatively, for example, one can use [https://docs.linuxserver.io/general/docker-compose Docker-compose provided by Linuxserver.io].
{{collapse/div|#CLI}}
{{collapse/div|#CLI}}
<syntaxhighlight lang="bash" class="mlw-continue">
<syntaxhighlight lang="bash" class="code-continue">
# docker-compose from linuxserver.io
# docker-compose from linuxserver.io
</syntaxhighlight>
</syntaxhighlight>
Line 34: Line 46:
sudo chmod +x /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
</syntaxhighlight>
</syntaxhighlight>
{{collapse/end}}
{{collapse/end}}
{{collapse/end}}


Line 46: Line 59:
=== Prune All ===
=== Prune All ===
Simple script that will prune all Docker ''containers'' and ''images'' that are not in use. If you want to use it, add the script somewhere in your <code>$PATH</code> to be accessible as shell command and make it executable.
Simple script that will prune all Docker ''containers'' and ''images'' that are not in use. If you want to use it, add the script somewhere in your <code>$PATH</code> to be accessible as shell command and make it executable.
<syntaxhighlight lang="shell" class="mlw-continue">
<syntaxhighlight lang="shell" class="code-continue" line="1">
docker-prune.sh
sudo nano /usr/local/bin/docker-prune.sh && sudo chmod +x /usr/local/bin/docker-prune.sh
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
#!/bin/bash
#!/bin/bash
docker image prune -a  
docker image prune -a
docker container prune
docker container prune
docker images prune
docker images prune
docker system prune
docker system prune
</syntaxhighlight><syntaxhighlight lang="shell" class="code-continue" line="1">
docker volume rm $(docker volume ls -qf dangling=true)
</syntaxhighlight>
</syntaxhighlight>
* Stack Overflow: [https://stackoverflow.com/a/41972043/6543935 Why is docker image eating up my disk space that is not used by docker]


=== Force update existing images with docker-compose ===
=== Force update existing images with docker-compose ===
<syntaxhighlight lang="shell" class="mlw-continue">
<syntaxhighlight lang="shell" class="code-continue">
docker-compose up --force-recreate --build -d
docker compose up --force-recreate --build -d
docker image prune -f
docker image prune -f
</syntaxhighlight>
</syntaxhighlight>
Line 81: Line 98:
* TechWorld with Nana: [https://youtu.be/3c-iBn73dDE <nowiki>Docker Tutorial for Beginners [FULL COURSE in 3 Hours]</nowiki>] ([https://youtu.be/jPdIRX6q4jA Docker Tutorial for Beginners])
* TechWorld with Nana: [https://youtu.be/3c-iBn73dDE <nowiki>Docker Tutorial for Beginners [FULL COURSE in 3 Hours]</nowiki>] ([https://youtu.be/jPdIRX6q4jA Docker Tutorial for Beginners])
* GitLab of Nana: [https://gitlab.com/nanuchi/techworld-js-docker-demo-app/-/tree/master techworld-js-docker-demo-app]
* GitLab of Nana: [https://gitlab.com/nanuchi/techworld-js-docker-demo-app/-/tree/master techworld-js-docker-demo-app]
== See also ==
* File: [[:File:Using Portainer with Docker and Docker Compose - Earthly Blog.pdf|Using Portainer with Docker and Docker Compose - Earthly Blog.pdf]]


{{AutoLangSwitch}}
{{AutoLangSwitch}}
Line 90: Line 111:
  | Прндл1 = Containers
  | Прндл1 = Containers
  | Прндл2 = DevOps and SRE
  | Прндл2 = DevOps and SRE
  | Стадий = 3
  | Стадий = 6
  | Фаза  = Разработване
  | Фаза  = Утвърждаване
  | Статус = Разутвърден
  | Статус = Утвърден
  | ИдтПт  = Spas
  | ИдтПт  = Spas
  | РзбПт  = {{REVISIONUSER}}
  | РзбПт  = Spas
  | АвтПт  = Spas
  | АвтПт  = Spas
  | УтвПт  = Spas
  | УтвПт  = {{REVISIONUSER}}
  | ИдтДт  = 28.05.2022
  | ИдтДт  = 28.05.2022
  | РзбДт  = {{Today}}
  | РзбДт  = 24.05.2023
  | АвтДт  = 28.08.2022
  | АвтДт  = 24.05.2023
  | УтвДт  = 8.09.2022
  | УтвДт  = {{Today}}
  | ИдтРв  = [[Special:Permalink/24238|24238]]
  | ИдтРв  = [[Special:Permalink/24238|24238]]
  | РзбРв  = {{REVISIONID}}
  | РзбРв  = [[Special:Permalink/32550|32550]]
  | АвтРв  =  
  | АвтРв  = [[Special:Permalink/32552|32552]]
  | РзАРв  = [[Special:Permalink/30658|30658]]
  | РзАРв  = [[Special:Permalink/32534|32534]]
  | УтвРв  =  
  | УтвРв  = {{REVISIONID}}
  | РзУРв  = [[Special:Permalink/31337|31337]]
  | РзУРв  = [[Special:Permalink/32537|32537]]
}}
}}
</div>
</div>
</noinclude>
</noinclude>

Latest revision as of 11:19, 22 September 2023

Dock­er In­stal­la­tion Steps

This sec­tion we gives fresh (Feb. 2023) ref­er­ences how to in­stall Dock­er and Dock­er Com­pose plu­g­in v.2.x on Ubun­tu.

Dep­re­cat­ed Dock­er In­stal­la­tion Steps

#Dep­re­cat­ed In­stal­la­tion Steps

In­stall Dock­er

In­stall Dock­er on Ubun­tu and oth­er De­bian based dis­tros.
sudo apt install docker.io curl
sudo usermod -aG docker "$USER"
Ref­er­ences:

In­stall Dock­er Com­pose

More in­for­ma­tion at Get start­ed with Dock­er Com­pose.
# docker-compose from github.com/docker/compose#where-to-get-docker-compose
sudo curl -L --fail \
https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64 \
-o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Al­ter­na­tive­ly, for ex­am­ple, one can use Dock­er-com­pose pro­vid­ed by Linuxserver​.io.

#CLI
# docker-compose from linuxserver.io
sudo curl -L --fail \
https://raw.githubusercontent.com/linuxserver/docker-docker-compose/master/run.sh \
-o /usr/local/bin/docker-compose && \
sudo chmod +x /usr/local/bin/docker-compose

Ba­sics Ex­am­ple

Here is a GitHub repos­i­to­ry that il­lus­trates at very ba­sic lev­el how to use Dock­er­file and docler-compose.yaml to de­ploy a Node.js ap­pli­ca­tion.

Mis­cel­la­neous

Prune All

Sim­ple script that will prune all Dock­er con­tain­ers and im­ages that are not in use. If you want to use it, add the script some­where in your $PATH to be ac­ces­si­ble as shell com­mand and make it ex­e­cutable.

sudo nano /usr/local/bin/docker-prune.sh && sudo chmod +x /usr/local/bin/docker-prune.sh
#!/bin/bash
docker image prune -a
docker container prune
docker images prune
docker system prune
docker volume rm $(docker volume ls -qf dangling=true)

Force up­date ex­ist­ing im­ages with dock­er-com­pose

docker compose up --force-recreate --build -d
docker image prune -f

Log-in to a Dock­er Con­tain­er

docker exec -it container(id|name) /bin/bash

Gen­er­ate Hashed Pass­word for Code-serv­er

printf 'your-password' | npx argon2-cli -e | sed 's/\$/$$/g'

De­mo App from Nana's Dock­er Tu­to­r­i­al for Be­gin­ners

See al­so