Ubuntu2404 Install Docker and Docker Compose: Difference between revisions
Line 333: | Line 333: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
If any items remain, repeat the relevant removal commands or check for dependencies. | If any items remain, repeat the relevant removal commands or check for dependencies. | ||
==Docker Compose container== |
Latest revision as of 21:16, 1 September 2025
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
- Now visit http://localhost:8080 on your browser
- 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.