Skip to content

Instantly share code, notes, and snippets.

@xmsi
Last active March 5, 2025 09:28
Show Gist options
  • Save xmsi/0c0d13201dd0b61c2d6e6fb66de2df02 to your computer and use it in GitHub Desktop.
Save xmsi/0c0d13201dd0b61c2d6e6fb66de2df02 to your computer and use it in GitHub Desktop.
Docker helper

Docker Engine, Compose, Portainer on Ubuntu 22

Docker Engine, Compose and Portainer installation on ubuntu 22. Optional: how to change default docker root folder (where images and containers are stored)

Install docker engine

tutorial video tested it works To install on Ubuntu 22 you should type these commands in your CLI

  1. $ curl -fsSl https://get.docker.com -o get-docker.sh
  2. $ sudo sh get-docker.sh
  3. $ sudo groupadd docker
  4. $ sudo usermod -aG docker ${USER}
    where ${USER} is a variable provided by UNIX-like operating systems that contains the name of the current user, this allows the current user's name to be automatically inserted into the command so that we can add it to the "docker" group.
  5. logout from system then log in back

Install docker compose

official web-site

  1. $ sudo curl -SL https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
  2. $ sudo chmod +x /usr/local/bin/docker-compose

Optional (Not required) Portainer WEB UI For docker

official web

$ docker run -d -p 8005: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 --http-enabled

Also check Dockage as a simple and powerful alternative of Portainer

Optional (Not required) Change default docker_root folder

tutorial web

  1. $ mkdir WHEN_YOU_WANT_NEW_ROOT
  2. $ sudo nano /etc/docker/daemon.json

inside

{ 
   "data-root": "/WHEN_YOU_WANT_NEW_ROOT"
}
  1. $ sudo systemctl restart docker
  2. $ docker info -f '{{ .DockerRootDir}}'

Commands

  1. docker cp storage/database.sql trc_for_prod-mysql-trc-1:/tmp/database.sql copy from local comp to docker container

Binding

volumes:
      - /var/www/html/node_modules
      - /var/www/html/public/fonts

These volumes prevent certain directories from being overwritten when using Docker bind mounts (-v). Here’s why:

1️⃣ /var/www/html/node_modules If you are using Node.js inside the container, the node_modules folder is generated inside the container during npm install. When mounting your local Laravel project (/var/www/html), Docker replaces the container’s directory with your local code. This means that if node_modules is not in a volume, it would get overwritten or deleted when mounting your local project. The volume ensures node_modules remains inside the container and is not affected by the local file system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment