Docker Basic Setup: Difference between revisions

From WikiMLT
Tags: Reverted Visual edit
Tag: Reverted
Line 114: Line 114:
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray">
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray">
docker volume (rm|prune) volume_name
docker volume (rm|prune) volume_name
</syntaxhighlight>Note when you are using <code>docker compose</code>, unless specify path in the left side on the ''<code>services:</code>  <code>container_name:</code> <code>volumes:</code>'' section docker will automatically create a volume /var/lib/docker/volumes/ named after the '''container_name''' underscore '''_''' and the name of the '''volume'''.<syntaxhighlight lang="shell">
</syntaxhighlight>Note when you are using <code>docker compose</code>, unless specify path in the left side on the ''<code>services:</code>  <code>container_name:</code> <code>volumes:</code>'' section docker will automatically create a volume /var/lib/docker/volumes/ named after the '''container_name''' underscore '''_''' and the name of the '''volume'''.
<syntaxhighlight lang="shell" class="code-continue">
docker-compose.yml # example 1
docker-compose.yml # example 1
</syntaxhighlight><syntaxhighlight lang="yaml" line="1" class="code-continue mlw-shell-gray">
</syntaxhighlight>
<syntaxhighlight lang="yaml" line="1" class="code-continue mlw-shell-gray">
version: "3"
services:
  container_name:
    image: image_name
    volumes:
    - ./base:/data
 
</syntaxhighlight>
<syntaxhighlight lang="bash" class=mlw-pre-wrap"">
The directory used as a volume is "./base" within the current directory where the "docker-compose.yml" is located.
</syntaxhighlight>
 
<syntaxhighlight lang="shell" class="code-continue">
docker-compose.yml # example 1
</syntaxhighlight>
<syntaxhighlight lang="yaml" line="1" class="code-continue mlw-shell-gray">
version: "3"
version: "3"
services:
services:
Line 124: Line 142:
     - ./base:/data
     - ./base:/data


</syntaxhighlight><syntaxhighlight lang="bash">
</syntaxhighlight>
<syntaxhighlight lang="bash" class=mlw-pre-wrap"">
The directory used as a volume is "./base" within the current directory where the "docker-compose.yml" is located.
The directory used as a volume is "./base" within the current directory where the "docker-compose.yml" is located.
</syntaxhighlight>
</syntaxhighlight>
=== Generate Hashed Password for Code-server ===
=== Generate Hashed Password for Code-server ===
<syntaxhighlight lang="shell" line="1">
<syntaxhighlight lang="shell" line="1">

Revision as of 10:26, 24 May 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

Vol­umes man­age­ment

docker volume
Usage:  docker volume COMMAND

Manage volumes

Commands:
  create      Create a volume
  inspect     Display detailed information on one or more volumes
  ls          List volumes
  prune       Remove all unused local volumes
  rm          Remove one or more volumes

Run 'docker volume COMMAND --help' for more information on a command.
docker volume create volume_name
docker volume ls
docker volume inspect volume_name
sudo ls -la /var/lib/docker/volumes/
docker volume (rm|prune) volume_name

Note when you are us­ing dock­er com­pose, un­less spec­i­fy path in the left side on the ser­vices: container_​​​name: vol­umes: sec­tion dock­er will au­to­mat­i­cal­ly cre­ate a vol­ume /​​​var/​​​lib/​​​docker/​​​volumes/​​​ named af­ter the container_​​​name un­der­score _ and the name of the vol­ume.

docker-compose.yml # example 1
version: "3"
services:
  container_name:
    image: image_name
    volumes:
    - ./base:/data
The directory used as a volume is "./base" within the current directory where the "docker-compose.yml" is located.
docker-compose.yml # example 1
version: "3"
services:
  container_name:
    image: image_name
    volumes:
    - ./base:/data
The directory used as a volume is "./base" within the current directory where the "docker-compose.yml" is located.

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