Ubuntu2404 Install Docker and Docker Compose

From CompleteNoobs
Revision as of 21:13, 1 September 2025 by AwesomO (talk | contribs) (Run container)
Jump to navigation Jump to search
Please Select a Licence from the LICENCE_HEADERS page
And place at top of your page
If no Licence is Selected/Appended, Default will be CC0

Default Licence IF there is no Licence placed below this notice! When you edit this page, you agree to release your contribution under the CC0 Licence

LICENCE: More information about the cc0 licence can be found here:
https://creativecommons.org/share-your-work/public-domain/cc0

The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.

You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Licence:

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.

For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.

1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:

   the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
   moral rights retained by the original author(s) and/or performer(s);
   publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
   rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
   rights protecting the extraction, dissemination, use and reuse of data in a Work;
   database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
   other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.

2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.

3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.

4. Limitations and Disclaimers.

   No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
   Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
   Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
   Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.

Preparation

Before we begin, make sure you're logged in with a user account that has sudo privileges.

Update System Packages

Update your package list to ensure you have the latest versions of packages:

sudo apt update && sudo apt upgrade -y

Install Docker Prerequisites

Install the necessary packages for Docker setup:

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

Setup Docker Repository

  • Add Docker's Official GPG Key:
  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  • Add the Docker Repository:
  echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker and Docker Compose

  • Update Package List Again:
  sudo apt update
  • Install Docker Engine, CLI, Containerd, and Additional Tools:
  sudo apt install -y docker-ce docker-ce-cli containerd.io python3-bs4 python3-requests docker-compose


Verify Installation

Check if Docker and Docker Compose are installed correctly:

docker --version
docker-compose --version

Configure User Permissions

To run Docker commands without sudo, add your user to the docker group:

sudo usermod -aG docker $USER

Note: After adding your user to the docker group, you'll need to log out and log back in for the changes to take effect. If you do not log out and back in, Or you do not add your $USER to the docker group, you will be required to use sudo in some cases. such as ..

a way to apply group changes without logging out and back in - tip:

exec sudo su -l $USER

This command will replace your current shell with a new login shell for your user, which will have the updated group memberships. Both of these methods will apply the group changes immediately, allowing you to use LXD commands without having to log out and back in.

Remember, these changes only apply to the current terminal session. If you open a new terminal window, you might need to run the command again or log out and back in for the changes to take effect system-wide.

If Installing Docker messed up your LXC/LXD Networking

To resolve networking conflicts between Docker and LXC containers on Ubuntu 24.04, enable IP forwarding on the host system:

  • Open the sysctl configuration file in your preferred editor

sudo $EDITOR /etc/sysctl.conf

  • Uncomment or add the following line (around line 28):
net.ipv4.ip_forward=1
  • Apply the updated configuration to enable IP forwarding:

sysctl -p

  • Restart the system to ensure all changes take effect.

This should resolve the networking issue for LXC containers when Docker is installed.

Install First Container/Image

Download the completenoobs container image, mediawiki with the completenoobs xml installed.

docker pull completenoobs/cnoobs-wiki:0.1

Run container

  • Quick Start

docker run -d -p 8080:80 completenoobs/cnoobs-wiki:0.1

  • Quick Start with Persistent Storage
docker run -d -p 8080:80 \
  -v completenoobs_mysql:/var/lib/mysql \
  -v completenoobs_images:/var/www/html/images \
  --name completenoobs_wiki \
  completenoobs/cnoobs-wiki:0.1
  • NOTE: The above docker run command is for quick testing, if you want to be able to export your wiki's database to an XML file you can backup and share, please use method in expanding info box below.

If you want to be able to Export Your MediaWiki Database to Dated XML File - use this docker run method:

To export your MediaWiki database to a dated XML file (e.g., 20250901.xml) and save it to the host’s ~/wiki-container directory, run the export script inside the Docker container and use a volume mount to write the file to the host.

Step 1: Create Host Directory
On the host, ensure the ~/wiki-container directory exists:

mkdir -p ~/wiki-container

Step 2: Run Container with Volume Mount
If your container isn’t already using a volume for ~/wiki-container, stop and remove it, then restart with a volume mount:

docker stop completenoobs_wiki
docker rm completenoobs_wiki
docker run -d -p 8080:80 \
  -v ~/wiki-container:/export \
  -v completenoobs_mysql:/var/lib/mysql \
  -v completenoobs_images:/var/www/html/images \
  --name completenoobs_wiki \
  completenoobs/cnoobs-wiki:0.1

Step 3: Run Export Script in Container
Access the container’s shell:

docker exec -it completenoobs_wiki bash

Inside the container, run the export script to create a dated XML file:

DATE=$(date +%Y%m%d)
php /var/www/html/maintenance/run.php dumpBackup.php --full --output=file:/export/$DATE.xml
exit

This writes the file (e.g., 20250901.xml) to /export in the container, which maps to ~/wiki-container on the host.

Step 4: Verify the File
On the host, check for the XML file:

ls ~/wiki-container

You should see a file like 20250901.xml.

Notes
- If you encounter permission issues, ensure the container’s user has write access to /export:

chmod -R 777 /export

- The script must be run inside the container, as it requires MediaWiki’s environment and database access.
- If your container uses a different volume setup, adjust the mount point accordingly.

Import MediaWiki XML File from Host Directory:

To import a wiki.xml file from the host’s ~/wiki-container directory into your MediaWiki instance running in a Docker container, use the importDump.php script inside the container. The ~/wiki-container directory is mounted as /export in the container, allowing the container to read the file.

Step 1: Place the XML File
On the host, move or copy the wiki.xml file to ~/wiki-container:

mv ~/Downloads/wiki.xml ~/wiki-container/

Verify the file is present:

ls ~/wiki-container

Step 2: Access the Container’s Shell
Enter the container’s shell:

docker exec -it completenoobs_wiki bash

Step 3: Run the Import Script
Inside the container, import the wiki.xml file:
Can check file is present in container with ls /export/

php /var/www/html/maintenance/run.php importDump.php /export/wiki.xml

Note: This imports the XML content into the MediaWiki database. For large files, this may take time.

Step 4: Rebuild Wiki Indexes (Optional but Recommended)
Rebuild the wiki’s indexes to ensure imported content is accessible:

php /var/www/html/maintenance/run.php rebuildall.php

Step 5: Exit the Container
Exit the container’s shell:

exit

Step 6: Verify the Import
Visit your wiki (e.g., http://localhost:8080) to check if the imported pages appear. If issues arise, check the container logs:

docker logs completenoobs_wiki

Notes
- Ensure the container has read access to /export. Fix permissions if needed:

chmod -R 777 /export

- If you want to overwrite existing pages, use the --no-updates flag with importDump.php.
- If the container wasn’t started with ~/wiki-container mounted as /export, restart it with:

docker run -d -p 8080:80 -v ~/wiki-container:/export --name completenoobs_wiki completenoobs/cnoobs-wiki:0.1
  • Due to (unknown) bug you might need to update the xml to download missing pages:

docker exec -it completenoobs_wiki /var/www/html/check_updates.sh

Change Admin Password:

By default, the admin user's password is AdminPass123!. It's highly recommended to change this immediately. You can do this either through the wiki's web interface or directly in the Docker terminal.

Method 1: Change Password via Web Interface
This is the easiest method. You can change your password directly from the wiki itself.

1. Log in to your wiki with the default credentials: admin / AdminPass123!.
2. Once logged in, click your username (admin) in the top-right corner of the page.
3. From the drop-down menu, select Preferences.
4. On the Preferences page, go to the Password tab.
5. Enter the current password (AdminPass123!), then enter your new password twice.
6. Click Change password.

Your password is now changed, and you will need to use the new one for future logins.

Method 2: Change Password via Terminal (No-Email Reset)
If you have forgotten the password or prefer to use the command line, you can reset it directly inside the Docker container using a MediaWiki maintenance script.

1. Access the container's shell with the following command from your host machine:

docker exec -it completenoobs_wiki bash

2. Once inside the container, use the changePassword.php maintenance script to change the password. This is the modern, recommended way to run MediaWiki maintenance scripts.

  • Change NEWPASSWORD to your new password
php /var/www/html/maintenance/run.php changePassword.php --user=admin --password=NEWPASSWORD

3. Type exit to leave the container's shell.

The admin password has now been reset. You can log in to your wiki with the new password.

Remove container

To completely remove the completenoobs/cnoobs-wiki:0.1 container and image from your Ubuntu 24.04 system, follow these steps. You can also remove associated persistent storage volumes if they were created.

Step 1: Stop and Remove the Container
If the container is running, stop it and then remove it.

docker stop completenoobs_wiki
docker rm completenoobs_wiki

Alternatively, stop and remove in one command:

docker rm -f completenoobs_wiki


Step 2: Remove the Docker Image
Remove the completenoobs/cnoobs-wiki:0.1 image.

docker rmi completenoobs/cnoobs-wiki:0.1

Note: If the image is in use by other containers, remove those containers first or use docker rmi -f completenoobs/cnoobs-wiki:0.1 to force removal (use with caution).

Step 3: Remove Persistent Storage Volumes (Optional)
If you used persistent storage, remove the associated volumes to free up space.

docker volume rm completenoobs_mysql completenoobs_images

Note: Ensure no other containers are using these volumes, as this will delete all stored data.

Step 4: Verify Removal
Check that the container, image, and volumes are removed.
- List all containers (including stopped ones):

docker ps -a

- List all images:

docker images

- List all volumes:

docker volume ls

If any items remain, repeat the relevant removal commands or check for dependencies.