Docker Basic Setup
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: Install Docker Engine on Ubuntu >> Uninstall old versions >> Install using the repository
- Docker Docs: Install the Compose plugin >> Install using the repository
- LinuxServer.io Docs: As an additional Docker usage reference and source of plenty of images
Deprecated Docker Installation Steps
Install Docker
Install Docker on Ubuntu and other Debian based distros.sudo apt install docker.io curl
sudo usermod -aG docker "$USER"
- 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.
# 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
Volumes management
- Docker: Manuals > Docker Engine > Storage > Volumes
- Docker: Reference > Compose file reference > Compose specification > Volumes top-level element
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 using docker compose
, unless specify path in the left side on the services:
container-name:
volumes:
section docker will automatically create a volume /var/lib/docker/volumes/ named after the container-name underscore _ and the name of the volume.
example 1
docker-compose.yml
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.
example 2
docker-compose.yml
version: "3"
services:
container-name:
image: image_name
volumes:
- base:/data
volumes:
base:
The directory used as a volume is "/var/lib/docker/volumes/container-name_base/_data" and it will be automatically created unles some additional options are specified within the "volumes:" section.
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
See also