Docker Basic Setup: Difference between revisions
From WikiMLT
m Text replacement - "mlw-continue" to "code-continue" |
|||
Line 12: | Line 12: | ||
== Install Docker Compose == | == Install Docker Compose == | ||
More information at [https://docs.docker.com/compose/gettingstarted/ Get started with Docker Compose].<syntaxhighlight lang="bash" class=" | 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=" | <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 25: | ||
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=" | <syntaxhighlight lang="bash" class="code-continue"> | ||
# docker-compose from linuxserver.io | # docker-compose from linuxserver.io | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 46: | Line 46: | ||
=== 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=" | <syntaxhighlight lang="shell" class="code-continue" line="1"> | ||
sudo nano /usr/local/bin/docker-prune.sh && sudo chmod +x /usr/local/bin/docker-prune.sh | sudo nano /usr/local/bin/docker-prune.sh && sudo chmod +x /usr/local/bin/docker-prune.sh | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 55: | Line 55: | ||
docker images prune | docker images prune | ||
docker system prune | docker system prune | ||
</syntaxhighlight><syntaxhighlight lang="shell" class=" | </syntaxhighlight><syntaxhighlight lang="shell" class="code-continue" line="1"> | ||
docker volume rm $(docker volume ls -qf dangling=true) | docker volume rm $(docker volume ls -qf dangling=true) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 62: | Line 62: | ||
=== Force update existing images with docker-compose === | === Force update existing images with docker-compose === | ||
<syntaxhighlight lang="shell" class=" | <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 |
Revision as of 07:28, 26 September 2022
Install Docker
Install Docker on Ubuntu and other Debian based distros.
sudo apt install docker.io curl
sudo usermod -aG docker "$USER"
References:
- Stack Overflow: What is docker.io in relation to docker-ce and docker-ee (now called "Mirantis Kubernetes Engine")?
- Collabora.com: The docker.io Debian package is back to life
Install Docker Compose
More information at Get started with Docker Compose.
# 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
Alternatively, for example, one can use Docker-compose provided 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
Basics Example
Here is a GitHub repository that illustrates at very basic level how to use Dockerfile
and docler-compose.yaml
to deploy a Node.js application.
- GitHub: Simple task manager
- GitHub: Simple task manager#CLI.md
Miscellaneous
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 $PATH
to be accessible as shell command and make it executable.
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 update existing images with docker-compose
docker-compose up --force-recreate --build -d
docker image prune -f
- Stack Overflow: How to update existing images with docker-compose?
Log-in to a Docker Container
docker exec -it container(id|name) /bin/bash
Generate Hashed Password for Code-server
printf 'your-password' | npx argon2-cli -e | sed 's/\$/$$/g'
- Code-server GitHub: FAQ – Can I store my password hashed?
Demo App from Nana's Docker Tutorial for Beginners
- TechWorld with Nana: Docker Tutorial for Beginners [FULL COURSE in 3 Hours] (Docker Tutorial for Beginners)
- GitLab of Nana: techworld-js-docker-demo-app