We are starting out with a per installed server with docker.
First thing that we need to do is update the server to we are using Ubuntu 20.04
sudo apt update && sudo apt upgrade -y
With the server updated it is time to get to the project the first part of the project that we are going to be working on is the "control file" this is a .ymal file that will tell docker and docker compose for you would like to set up your apps that you will be using for your project.
sudo nano docker-compose.yml
version: '3.8' services: db: image: mariadb:latest container_name: nextcloud_db restart: always environment: - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} - MYSQL_DATABASE=${MYSQL_DATABASE} - MYSQL_USER=${MYSQL_USER} - MYSQL_PASSWORD=${MYSQL_PASSWORD} volumes: - secure_data:/var/lib/mysql networks: - nextcloud_network app: image: nextcloud:latest container_name: nextcloud_app ports: - 8080:80 restart: always environment: - MYSQL_HOST=db - MYSQL_DATABASE=${MYSQL_DATABASE} - MYSQL_USER=${MYSQL_USER} - MYSQL_PASSWORD=${MYSQL_PASSWORD} depends_on: - db volumes: - nextcloud_data:/var/www/html networks: - nextcloud_network volumes: secure_data: driver: local driver_opts: type: none device: /var/lib/docker-volumes/mariadb_secure_data o: bind nextcloud_data: driver: local driver_opts: type: none device: /var/lib/docker-volumes/nextcloud_data o: bind networks: nextcloud_network:
version: '3.8'
services:
db:
image: mariadb:latest
container_name: nextcloud_db
restart: always
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
volumes:
- secure_data:/var/lib/mysql
networks:
- nextcloud_network
app:
image: nextcloud:latest
container_name: nextcloud_app
ports:
- 8080:80
restart: always
environment:
- MYSQL_HOST=db
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
depends_on:
- db
volumes:
- nextcloud_data:/var/www/html
networks:
- nextcloud_network
volumes:
secure_data:
driver: local
driver_opts:
type: none
device: /var/lib/docker-volumes/mariadb_secure_data
o: bind
nextcloud_data:
driver: local
driver_opts:
type: none
device: /var/lib/docker-volumes/nextcloud_data
o: bind
networks:
nextcloud_network:
sudo nano .env
MYSQL_ROOT_PASSWORD=your_root_password MYSQL_DATABASE=your_database MYSQL_USER=your_user MYSQL_PASSWORD=your_password
MYSQL_ROOT_PASSWORD=your_root_password
MYSQL_DATABASE=your_database
MYSQL_USER=your_user
MYSQL_PASSWORD=your_password
use the chmod command to restrict permissions for the file to that of the user that has made the file
sudo chmod 600 .env
Before we start up the project we are gooing to need to make some more folders so that we can set the permissions for them
sudo mkdir -p /var/lib/docker-volumes/mariadb_secure_data
sudo mkdir -p /var/lib/docker-volumes/nextcloud_data
Next we will set the permissions of the to folders that we have made with chmod but this time we are going to set them to 700 which means that the root account is the only one that can interact with the folders
sudo chmod 700 /var/lib/docker-volumes/mariadb_secure_data
sudo chmod -R 700 /var/lib/docker-volumes/nextcloud_data
last we are going to use chown to set ownership of a folder where nextcloud will store your data.
sudo chown -R www-data:www-data /var/lib/docker-volumes/nextcloud_data
With all of this done it is time to start this project up
sudo docker compose up -d