Skip to content

Installing Docker

Starting

Maybe you have never used docker before, I did (ofcourse). But each time I use it again, I have to lookup how to exactly install it, because there are some commands. Personally I always use docker-compose, why? Because I never need the regular docker. This post will also be my new guide, as I normally use a link from my bookmarks. For this whole post I'm going to assume you have sudo rights.

Do note, the link above is updated, my website is not. So use it at your own risk.

Downloading and installing

This guide is only for ubuntu, as the installation for the other distro's slightly differ.

Go ahead and login to your container/vm, and paste the following commands:

apt update
apt install ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc

Don't get scared, the > marks are supposed to be there, and will dissapear.

tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
Then make sure you update the system by using:
apt update
Now, install the packages
apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Starting up docker

Docker should automatically start up, but to make sure it has started you can check, and start with the following commands:

systemctl status docker
systemctl start docker
If you really want to make sure the installation has succeeded. This will download a test image and runs a test container, when it prints the confirmation, it will automatically stop itself.
docker run hello-world

Setting up a container/service

The following instructions will differ from your use case, but below I will start a homepage container. Create a folder for you docker container, and create the docker-compose.yml:

mkdir container-1
cd container-1
nano docker-compose.yml
I have posted the basic config from the homepage documentation:
services:
  homepage:
    image: ghcr.io/gethomepage/homepage:latest
    container_name: homepage
    ports:
      - 8080:3000 # Lan/Container
    volumes:
      - /path/to/config:/app/config # Make sure your local config directory exists
      - /var/run/docker.sock:/var/run/docker.sock:ro # (optional) For docker integrations
    environment:
      HOMEPAGE_ALLOWED_HOSTS: yourdomain.com
So to explain it further;
- The 'image:', is where docker pulls the software from. This should be the link to the repository.
- The 'container_name', is the name, your container gets. As simple as that.
- The 'ports:' section, is where you assign ports to your container. The left part '8080', is the port you assign to your network, to reach the container. Inside the container, the right part '3000', is the port the service listens to. The port outside your container, can be anything you want.
- The 'volumes:' section, is where you assign your directories to, again, the left side is outside of the container, the right side is for the service itself.
- The 'environment:' section, is where you set settings, as in this example the domain name of the site. Its also common to create a seperate variables file, I will dive into that in the next part.

Environment

If you have a lot of environment settings, it might be usefull to put them in a seperate file. This will tidy up the configuration file. Go ahead and create the environment file:

nano .env
The file will look like the following, ofcourse, change to your own settings (this example is from my owncloud):
1
2
3
4
5
OWNCLOUD_DOMAIN=localhost:8080
OWNCLOUD_TRUSTED_DOMAINS=localhost,192.168.20.51,your.domain.com,192.168.20.44
ADMIN_USERNAME=username
ADMIN_PASSWORD=password
HTTP_PORT=3600
And the configuration file will look like the following:
environment:
  - OWNCLOUD_DOMAIN=${OWNCLOUD_DOMAIN}
  - OWNCLOUD_TRUSTED_DOMAINS=${OWNCLOUD_TRUSTED_DOMAINS}
  - OWNCLOUD_DB_TYPE=mysql
  - OWNCLOUD_DB_NAME=owncloud
  - OWNCLOUD_DB_USERNAME=owncloud
  - OWNCLOUD_DB_PASSWORD=owncloud
  - OWNCLOUD_DB_HOST=mariadb
  - OWNCLOUD_ADMIN_USERNAME=${ADMIN_USERNAME}
  - OWNCLOUD_ADMIN_PASSWORD=${ADMIN_PASSWORD}
  - OWNCLOUD_MYSQL_UTF8MB4=true
  - OWNCLOUD_REDIS_ENABLED=true
  - OWNCLOUD_REDIS_HOST=redis

As you can see, I have more environment settings in the configuration, then in the env file. Don't ask me why, but that's apparently the way I did it when I installed this container

Starting a container

To start up the container you created, use the following command in the directory your docker-compose.yml file is located:

docker compose up -d

Status Docker-compose

With the following command you can see the status of the container:

docker compose ps
And the expected output for my container:
root@Homepage:~/homepage# docker compose ps
NAME       IMAGE                                 COMMAND                  SERVICE    CREATED        STATUS                  PORTS
homepage   ghcr.io/gethomepage/homepage:latest   "docker-entrypoint.s…"   homepage   3 months ago   Up 3 months (healthy)   0.0.0.0:3001->3000/tcp, [::]:3001->3000/tcp

Status Docker

With the following command you can see the status of all the containers:

docker ps
And the expected output for my container:
root@Homepage:~/homepage# docker ps
CONTAINER ID   IMAGE                                 COMMAND                  CREATED        STATUS                  PORTS                                         NAMES
b24d77f01178   ghcr.io/gethomepage/homepage:latest   "docker-entrypoint.s…"   3 months ago   Up 3 months (healthy)   0.0.0.0:3001->3000/tcp, [::]:3001->3000/tcp   homepage

I hope that was enough explanation to get you started with docker compose.